private static void doLoad(IndexRConfig config, MyOptions options, String outputPath, Path tmpPath) throws Exception {
        TableSchema schema = options.schemaPath == null ? null : JsonUtil.load(Paths.get(options.schemaPath), TableSchema.class);
        Preconditions.checkState(options.schemaPath != null, "Please specify schema path by -C");
        Preconditions.checkState(schema.schema != null, "Illegal schame");

        List<String> csvColNames = null;
        if (options.headerPath != null) {
            csvColNames = Arrays.asList(IOUtils.toString(new FileInputStream(options.headerPath), "UTF-8").split(options.spliter));
        }
        List<String> csvPaths = options.csvPath == null ? Collections.emptyList() : IOUtil.wildcardFiles(options.csvPath);

        CSVSegmentLoader loader = new CSVSegmentLoader(
                "tmp_gen_name",
                schema,
                csvColNames,
                csvPaths,
                tmpPath,
                options.spliter,
                SegmentMode.fromNameWithCompress(options.mode, !options.notcompress));

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                loader.stop();
            }
        });

        loader.load();
        if (!options.quiet) {
            System.out.printf("Loaded [%d] rows from csv files: %s\n", loader.rowCount(), csvPaths);
        }

        if (loader.interrupted) {
            return;
        }

        DPSegment segment = loader.done();

        URI uri = URI.create(outputPath);
        Configuration fsConfig = new Configuration();
        fsConfig.set("fs.hdfs.impl", DistributedFileSystem.class.getName());
        FileSystem fileSystem = FileSystem.get(uri, fsConfig);

        org.apache.hadoop.fs.Path realPath = new org.apache.hadoop.fs.Path(outputPath);
        if (fileSystem.exists(realPath)) {
            if (!options.quiet) {
                System.out.printf("Found file at [%s], remove it first...\n", fileSystem.resolvePath(realPath));
            }
            fileSystem.delete(realPath, false);
        }
        SegmentHelper.uploadSegment(segment, fileSystem, realPath, false);
        if (!options.quiet) {
            System.out.printf("Generated segment [%s]\n", fileSystem.resolvePath(realPath));
        }
    }
TODO handle the case when row number is larger then {@link StorageSegment#MAX_ROW_COUNT}.
indexr-server/src/main/java/io/indexr/tool/CSVSegmentLoader.java