All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marklogic.flux.impl.export.ExportAvroFilesCommand Maven / Gradle / Ivy

There is a newer version: 1.0.0.ea1
Show newest version
/*
 * Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
 */
package com.marklogic.flux.impl.export;

import com.marklogic.flux.api.AvroFilesExporter;
import com.marklogic.flux.api.ReadRowsOptions;
import com.marklogic.flux.api.WriteSparkFilesOptions;
import picocli.CommandLine;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

@CommandLine.Command(
    name = "export-avro-files",
    description = "Read rows via Optic from MarkLogic and write them to Avro files on a local filesystem, HDFS, or S3 " +
        "using Spark's support defined at %nhttps://spark.apache.org/docs/latest/sql-data-sources-avro.html ."
)
public class ExportAvroFilesCommand extends AbstractExportRowsToFilesCommand implements AvroFilesExporter {

    @CommandLine.Mixin
    private WriteAvroFilesParams writeParams = new WriteAvroFilesParams();

    @Override
    protected String getWriteFormat() {
        return "avro";
    }

    @Override
    protected WriteStructuredFilesParams getWriteFilesParams() {
        return writeParams;
    }

    public static class WriteAvroFilesParams extends WriteStructuredFilesParams implements WriteSparkFilesOptions {

        @CommandLine.Option(
            names = "-P",
            description = "Specify any Spark Avro option defined at " +
                "%nhttps://spark.apache.org/docs/latest/sql-data-sources-avro.html; e.g. -Pcompression=bzip2."
        )
        private Map additionalOptions = new HashMap<>();

        @Override
        public Map get() {
            return additionalOptions;
        }

        @Override
        public WriteSparkFilesOptions additionalOptions(Map options) {
            this.additionalOptions = options;
            return this;
        }
    }

    @Override
    public AvroFilesExporter from(Consumer consumer) {
        consumer.accept(readParams);
        return this;
    }

    @Override
    public AvroFilesExporter from(String opticQuery) {
        readParams.opticQuery(opticQuery);
        return this;
    }

    @Override
    public AvroFilesExporter to(Consumer consumer) {
        consumer.accept(writeParams);
        return this;
    }

    @Override
    public AvroFilesExporter to(String path) {
        writeParams.path(path);
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy