Search in sources :

Example 1 with CarbonLoadModelBuilder

use of org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder in project carbondata by apache.

the class CarbonWriterBuilder method buildLoadModel.

/**
 * Build a {@link CarbonLoadModel}
 */
private CarbonLoadModel buildLoadModel(CarbonTable table) throws InvalidLoadOptionException, IOException {
    Map<String, String> options = new HashMap<>();
    if (sortColumns != null) {
        options.put("sort_columns", Strings.mkString(sortColumns, ","));
    }
    CarbonLoadModelBuilder builder = new CarbonLoadModelBuilder(table);
    return builder.build(options);
}
Also used : HashMap(java.util.HashMap) CarbonLoadModelBuilder(org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder)

Example 2 with CarbonLoadModelBuilder

use of org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder in project carbondata by apache.

the class HiveCarbonUtil method getCarbonLoadModel.

public static CarbonLoadModel getCarbonLoadModel(String tableName, String databaseName, String location, String sortColumnsString, String[] columns, String[] columnTypes, Configuration configuration) {
    CarbonLoadModel loadModel;
    CarbonTable carbonTable;
    try {
        String schemaFilePath = CarbonTablePath.getSchemaFilePath(location, configuration);
        AbsoluteTableIdentifier absoluteTableIdentifier = AbsoluteTableIdentifier.from(location, databaseName, tableName, "");
        if (FileFactory.getCarbonFile(schemaFilePath).exists()) {
            carbonTable = SchemaReader.readCarbonTableFromStore(absoluteTableIdentifier);
            carbonTable.setTransactionalTable(true);
        } else {
            String carbonDataFile = CarbonUtil.getFilePathExternalFilePath(location, configuration);
            if (carbonDataFile == null) {
                carbonTable = CarbonTable.buildFromTableInfo(getTableInfo(tableName, databaseName, location, sortColumnsString, columns, columnTypes, new ArrayList<>()));
            } else {
                carbonTable = CarbonTable.buildFromTableInfo(SchemaReader.inferSchema(absoluteTableIdentifier, false, configuration));
            }
            carbonTable.setTransactionalTable(false);
        }
    } catch (SQLException | IOException e) {
        throw new RuntimeException("Unable to fetch schema for the table: " + tableName, e);
    }
    CarbonLoadModelBuilder carbonLoadModelBuilder = new CarbonLoadModelBuilder(carbonTable);
    Map<String, String> options = new HashMap<>();
    options.put("fileheader", Strings.mkString(columns, ","));
    try {
        loadModel = carbonLoadModelBuilder.build(options, System.currentTimeMillis(), "");
    } catch (InvalidLoadOptionException | IOException e) {
        throw new RuntimeException(e);
    }
    loadModel.setSkipParsers();
    loadModel.setMetrics(new DataLoadMetrics());
    return loadModel;
}
Also used : InvalidLoadOptionException(org.apache.carbondata.common.exceptions.sql.InvalidLoadOptionException) DataLoadMetrics(org.apache.carbondata.core.util.DataLoadMetrics) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) IOException(java.io.IOException) CarbonLoadModelBuilder(org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) CarbonLoadModel(org.apache.carbondata.processing.loading.model.CarbonLoadModel)

Example 3 with CarbonLoadModelBuilder

use of org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder in project carbondata by apache.

the class CarbonWriterBuilder method buildLoadModel.

/**
 * Build a {@link CarbonLoadModel}
 */
private CarbonLoadModel buildLoadModel(CarbonTable table, long timestamp, String taskNo, Map<String, String> options) throws InvalidLoadOptionException, IOException {
    if (options == null) {
        options = new HashMap<>();
    }
    CarbonLoadModelBuilder builder = new CarbonLoadModelBuilder(table);
    CarbonLoadModel model = builder.build(options, timestamp, taskNo);
    setCsvHeader(model);
    return model;
}
Also used : CarbonLoadModel(org.apache.carbondata.processing.loading.model.CarbonLoadModel) CarbonLoadModelBuilder(org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder)

Example 4 with CarbonLoadModelBuilder

use of org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder in project hetu-core by openlookeng.

the class CarbondataHetuOutputFormat method createCarbonLoadModel.

private CarbonLoadModel createCarbonLoadModel(Configuration configuration, Properties tableProperties) throws IOException {
    String[] tableUniqueName = tableProperties.get("name").toString().split("\\.");
    String databaseName = tableUniqueName[0];
    String tableName = tableUniqueName[1];
    String tablePath = tableProperties.get("location").toString();
    CarbonTable carbonTable = CarbonTable.buildFromTablePath(tableName, databaseName, tablePath, "");
    CarbonLoadModelBuilder carbonLoadModelBuilder = new CarbonLoadModelBuilder(carbonTable);
    try {
        return carbonLoadModelBuilder.build(carbonTable.getTableInfo().getFactTable().getTableProperties(), System.currentTimeMillis(), "1");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) IOException(java.io.IOException) CarbonLoadModelBuilder(org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder)

Aggregations

CarbonLoadModelBuilder (org.apache.carbondata.processing.loading.model.CarbonLoadModelBuilder)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)2 CarbonLoadModel (org.apache.carbondata.processing.loading.model.CarbonLoadModel)2 SQLException (java.sql.SQLException)1 InvalidLoadOptionException (org.apache.carbondata.common.exceptions.sql.InvalidLoadOptionException)1 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)1 DataLoadMetrics (org.apache.carbondata.core.util.DataLoadMetrics)1