Search in sources :

Example 31 with CarbonTable

use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.

the class CarbonTableReader method parseCarbonMetadata.

/**
   * parse carbon metadata into cc(CarbonTableReader cache)
   */
public CarbonTable parseCarbonMetadata(SchemaTableName table) {
    CarbonTable result = null;
    try {
        CarbonTableCacheModel cache = cc.getOrDefault(table, new CarbonTableCacheModel());
        if (cache.isValid())
            return cache.carbonTable;
        //Step1: get table meta path, load carbon table param
        String storePath = config.getStorePath();
        cache.carbonTableIdentifier = new CarbonTableIdentifier(table.getSchemaName(), table.getTableName(), UUID.randomUUID().toString());
        cache.carbonTablePath = PathFactory.getInstance().getCarbonTablePath(storePath, cache.carbonTableIdentifier);
        cc.put(table, cache);
        //Step2: check file existed? read schema file
        ThriftReader.TBaseCreator createTBase = new ThriftReader.TBaseCreator() {

            public TBase create() {
                return new org.apache.carbondata.format.TableInfo();
            }
        };
        ThriftReader thriftReader = new ThriftReader(cache.carbonTablePath.getSchemaFilePath(), createTBase);
        thriftReader.open();
        org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
        thriftReader.close();
        // Step3: Transform Format Level TableInfo to Code Level TableInfo
        SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
        TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, table.getSchemaName(), table.getTableName(), storePath);
        wrapperTableInfo.setMetaDataFilepath(CarbonTablePath.getFolderContainingFile(cache.carbonTablePath.getSchemaFilePath()));
        // Step4: Load metadata info into CarbonMetadata
        CarbonMetadata.getInstance().loadTableMetadata(wrapperTableInfo);
        cache.tableInfo = wrapperTableInfo;
        cache.carbonTable = CarbonMetadata.getInstance().getCarbonTable(cache.carbonTableIdentifier.getTableUniqueName());
        result = cache.carbonTable;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return result;
}
Also used : KeyGenException(org.apache.carbondata.core.keygenerator.KeyGenException) IndexBuilderException(org.apache.carbondata.core.datastore.exception.IndexBuilderException) IOException(java.io.IOException) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) ThriftReader(org.apache.carbondata.core.reader.ThriftReader) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) SchemaConverter(org.apache.carbondata.core.metadata.converter.SchemaConverter) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)

Example 32 with CarbonTable

use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.

the class CarbondataMetadata method getTableMetadata.

private ConnectorTableMetadata getTableMetadata(SchemaTableName schemaTableName) {
    if (!listSchemaNamesInternal().contains(schemaTableName.getSchemaName())) {
        return null;
    }
    CarbonTable carbonTable = carbonTableReader.getTable(schemaTableName);
    if (carbonTable == null) {
        return null;
    }
    List<ColumnMetadata> columnsMetaList = new LinkedList<>();
    List<CarbonColumn> carbonColumns = carbonTable.getCreateOrderColumn(schemaTableName.getTableName());
    for (CarbonColumn col : carbonColumns) {
        //show columns command will return these data
        Type columnType = CarbondataType2SpiMapper(col.getColumnSchema());
        ColumnMetadata columnMeta = new ColumnMetadata(col.getColumnSchema().getColumnName(), columnType);
        columnsMetaList.add(columnMeta);
    }
    //carbondata connector's table metadata
    return new ConnectorTableMetadata(schemaTableName, columnsMetaList);
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Types.checkType(org.apache.carbondata.presto.Types.checkType) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)

Example 33 with CarbonTable

use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.

the class TableDictionaryGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    // enable lru cache by setting cache size
    CarbonProperties.getInstance().addProperty(CarbonCommonConstants.CARBON_MAX_DRIVER_LRU_CACHE_SIZE, "10");
    // Create two column schemas and dimensions for the table
    empColumnSchema = new ColumnSchema();
    empColumnSchema.setColumnName("empNameCol");
    empColumnSchema.setColumnUniqueId("empNameCol");
    empColumnSchema.setDimensionColumn(true);
    empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
    empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
    ageColumnSchema = new ColumnSchema();
    ageColumnSchema.setColumnName("empNameCol");
    ageColumnSchema.setColumnUniqueId("empNameCol");
    ageColumnSchema.setDimensionColumn(true);
    ageColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
    ageDimension = new CarbonDimension(ageColumnSchema, 0, 0, 0, 0, 0);
    // Create a Table
    tableSchema = new TableSchema();
    tableSchema.setTableName("TestTable");
    tableSchema.setListOfColumns(Arrays.asList(empColumnSchema, ageColumnSchema));
    CarbonMetadata metadata = CarbonMetadata.getInstance();
    tableInfo = new TableInfo();
    tableInfo.setFactTable(tableSchema);
    tableInfo.setTableUniqueName("TestTable");
    tableInfo.setDatabaseName("test");
    storePath = System.getProperty("java.io.tmpdir") + "/tmp";
    tableInfo.setStorePath(storePath);
    CarbonTable carbonTable = new CarbonTable();
    carbonTable.loadCarbonTable(tableInfo);
    // Add the created table to metadata
    metadata.addCarbonTable(carbonTable);
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) CarbonMetadata(org.apache.carbondata.core.metadata.CarbonMetadata) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Before(org.junit.Before)

Example 34 with CarbonTable

use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.

the class ServerDictionaryGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    // enable lru cache by setting cache size
    CarbonProperties.getInstance().addProperty(CarbonCommonConstants.CARBON_MAX_DRIVER_LRU_CACHE_SIZE, "10");
    // Create two column schemas and dimensions for the table
    empColumnSchema = new ColumnSchema();
    empColumnSchema.setColumnName("empNameCol");
    empColumnSchema.setColumnUniqueId("empNameCol");
    empColumnSchema.setDimensionColumn(true);
    empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
    empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
    ageColumnSchema = new ColumnSchema();
    ageColumnSchema.setColumnName("empNameCol");
    ageColumnSchema.setColumnUniqueId("empNameCol");
    ageColumnSchema.setDimensionColumn(true);
    ageColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
    ageDimension = new CarbonDimension(ageColumnSchema, 0, 0, 0, 0, 0);
    // Create a Table
    tableSchema = new TableSchema();
    tableSchema.setTableName("TestTable");
    tableSchema.setListOfColumns(Arrays.asList(empColumnSchema, ageColumnSchema));
    CarbonMetadata metadata = CarbonMetadata.getInstance();
    tableInfo = new TableInfo();
    tableInfo.setFactTable(tableSchema);
    tableInfo.setTableUniqueName("TestTable");
    tableInfo.setDatabaseName("test");
    storePath = System.getProperty("java.io.tmpdir") + "/tmp";
    tableInfo.setStorePath(storePath);
    CarbonTable carbonTable = new CarbonTable();
    carbonTable.loadCarbonTable(tableInfo);
    // Add the created table to metadata
    metadata.addCarbonTable(carbonTable);
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) CarbonMetadata(org.apache.carbondata.core.metadata.CarbonMetadata) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Before(org.junit.Before)

Example 35 with CarbonTable

use of org.apache.carbondata.core.metadata.schema.table.CarbonTable in project carbondata by apache.

the class CarbonMetadataTest method testGetCarbonDimensionBasedOnColIdentifierWhenChildDimensionColumnEqualsColumnIdentifier.

@Test
public void testGetCarbonDimensionBasedOnColIdentifierWhenChildDimensionColumnEqualsColumnIdentifier() {
    CarbonTable carbonTable = new CarbonTable();
    String columnIdentifier = "9";
    final List<CarbonDimension> carbonDimensions = new ArrayList();
    ColumnSchema colSchema1 = new ColumnSchema();
    ColumnSchema colSchema2 = new ColumnSchema();
    colSchema1.setColumnUniqueId("1");
    carbonDimensions.add(new CarbonDimension(colSchema1, 1, 1, 2, 1));
    final List<CarbonDimension> carbonChildDimensions = new ArrayList();
    ColumnSchema colSchema3 = new ColumnSchema();
    colSchema3.setColumnUniqueId("9");
    colSchema2.setColumnUniqueId("2");
    carbonChildDimensions.add(new CarbonDimension(colSchema3, 1, 1, 2, 1));
    new MockUp<CarbonTable>() {

        @Mock
        public String getFactTableName() {
            return "carbonTestTable";
        }

        @Mock
        public List<CarbonDimension> getDimensionByTableName(String tableName) {
            return carbonDimensions;
        }
    };
    new MockUp<CarbonDimension>() {

        @Mock
        public int numberOfChild() {
            return 1;
        }

        @Mock
        public List<CarbonDimension> getListOfChildDimensions() {
            return carbonChildDimensions;
        }
    };
    CarbonDimension expectedResult = carbonChildDimensions.get(0);
    CarbonDimension actualResult = carbonMetadata.getCarbonDimensionBasedOnColIdentifier(carbonTable, columnIdentifier);
    assertEquals(expectedResult, actualResult);
}
Also used : CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) MockUp(mockit.MockUp) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) Test(org.junit.Test)

Aggregations

CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)37 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)13 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)9 CarbonMetadata (org.apache.carbondata.core.metadata.CarbonMetadata)8 ArrayList (java.util.ArrayList)7 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)6 IOException (java.io.IOException)5 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)5 CarbonTableIdentifier (org.apache.carbondata.core.metadata.CarbonTableIdentifier)5 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)5 File (java.io.File)4 DataType (org.apache.carbondata.core.metadata.datatype.DataType)4 TableSchema (org.apache.carbondata.core.metadata.schema.table.TableSchema)4 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)4 Expression (org.apache.carbondata.core.scan.expression.Expression)4 Test (org.junit.Test)4 FilterResolverIntf (org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf)3 CarbonQueryPlan (org.apache.carbondata.core.scan.model.CarbonQueryPlan)3 QueryModel (org.apache.carbondata.core.scan.model.QueryModel)3 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)3