use of org.apache.carbondata.core.metadata.schema.table.TableSchemaBuilder in project carbondata by apache.
the class HiveCarbonUtil method getTableInfo.
private static TableInfo getTableInfo(String tableName, String databaseName, String location, String sortColumnsString, String[] columns, String[] columnTypes, List<String> partitionColumns) throws SQLException {
TableInfo tableInfo = new TableInfo();
TableSchemaBuilder builder = new TableSchemaBuilder();
builder.tableName(tableName);
List<String> sortColumns = new ArrayList<>();
if (sortColumnsString != null) {
sortColumns = Arrays.asList(sortColumnsString.toLowerCase().split("\\,"));
}
PartitionInfo partitionInfo = null;
AtomicInteger integer = new AtomicInteger();
List<StructField> partitionStructFields = new ArrayList<>();
for (int i = 0; i < columns.length; i++) {
DataType dataType = DataTypeUtil.convertHiveTypeToCarbon(columnTypes[i]);
Field field = new Field(columns[i].toLowerCase(), dataType);
if (partitionColumns.contains(columns[i])) {
partitionStructFields.add(new StructField(columns[i].toLowerCase(), dataType, field.getChildren()));
} else {
builder.addColumn(new StructField(columns[i].toLowerCase(), dataType, field.getChildren()), integer, sortColumns.contains(columns[i]), false);
}
}
if (!partitionStructFields.isEmpty()) {
List<ColumnSchema> partitionColumnSchemas = new ArrayList<>();
for (StructField partitionStructField : partitionStructFields) {
partitionColumnSchemas.add(builder.addColumn(partitionStructField, integer, sortColumns.contains(partitionStructField.getFieldName()), false));
}
partitionInfo = new PartitionInfo(partitionColumnSchemas, PartitionType.NATIVE_HIVE);
}
TableSchema tableSchema = builder.build();
SchemaEvolution schemaEvol = new SchemaEvolution();
List<SchemaEvolutionEntry> schemaEvolutionEntry = new ArrayList<>();
schemaEvolutionEntry.add(new SchemaEvolutionEntry());
schemaEvol.setSchemaEvolutionEntryList(schemaEvolutionEntry);
tableSchema.setSchemaEvolution(schemaEvol);
tableSchema.setPartitionInfo(partitionInfo);
tableInfo.setDatabaseName(databaseName);
tableInfo.setTablePath(location);
tableInfo.setFactTable(tableSchema);
tableInfo.setTableUniqueName(databaseName + "_" + tableName);
return tableInfo;
}
use of org.apache.carbondata.core.metadata.schema.table.TableSchemaBuilder in project carbondata by apache.
the class CarbonWriterBuilder method buildCarbonTable.
/**
* Build a {@link CarbonTable}
*/
private CarbonTable buildCarbonTable() {
TableSchemaBuilder tableSchemaBuilder = TableSchema.builder();
if (blockSize > 0) {
tableSchemaBuilder = tableSchemaBuilder.blockSize(blockSize);
}
if (blockletSize > 0) {
tableSchemaBuilder = tableSchemaBuilder.blockletSize(blockletSize);
}
if (pageSizeInMb > 0) {
tableSchemaBuilder = tableSchemaBuilder.pageSizeInMb(pageSizeInMb);
}
tableSchemaBuilder.enableLocalDictionary(isLocalDictionaryEnabled);
tableSchemaBuilder.localDictionaryThreshold(localDictionaryThreshold);
List<String> sortColumnsList = new ArrayList<>();
if (sortColumns == null) {
// user passed size 4 but supplied only 2 fileds
for (Field field : schema.getFields()) {
if (null != field) {
if (field.getDataType() == DataTypes.STRING || field.getDataType() == DataTypes.DATE || field.getDataType() == DataTypes.TIMESTAMP) {
sortColumnsList.add(field.getFieldName());
}
}
}
sortColumns = new String[sortColumnsList.size()];
sortColumns = sortColumnsList.toArray(sortColumns);
} else {
sortColumnsList = Arrays.asList(sortColumns);
}
ColumnSchema[] sortColumnsSchemaList = new ColumnSchema[sortColumnsList.size()];
List<String> invertedIdxColumnsList = new ArrayList<>();
if (null != invertedIndexColumns) {
invertedIdxColumnsList = Arrays.asList(invertedIndexColumns);
}
Field[] fields = schema.getFields();
buildTableSchema(fields, tableSchemaBuilder, sortColumnsList, sortColumnsSchemaList, invertedIdxColumnsList);
tableSchemaBuilder.setSortColumns(Arrays.asList(sortColumnsSchemaList));
String tableName;
String dbName;
dbName = "";
tableName = "_tempTable-" + UUID.randomUUID().toString() + "_" + timestamp;
TableSchema schema = tableSchemaBuilder.build();
schema.setTableName(tableName);
CarbonTable table = CarbonTable.builder().tableName(schema.getTableName()).databaseName(dbName).tablePath(path).tableSchema(schema).isTransactionalTable(false).build();
return table;
}
Aggregations