Search in sources :

Example 46 with CarbonTableIdentifier

use of org.apache.carbondata.core.metadata.CarbonTableIdentifier in project carbondata by apache.

the class CarbonTableIdentifierTest method equalsTestWithSimilarObject.

@Test
public void equalsTestWithSimilarObject() {
    CarbonTableIdentifier carbonTableIdentifierTest = new CarbonTableIdentifier("DatabseName", "tableName", "tableId");
    Boolean res = carbonTableIdentifier.equals(carbonTableIdentifierTest);
    Assert.assertTrue(res);
}
Also used : CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) Test(org.junit.Test)

Example 47 with CarbonTableIdentifier

use of org.apache.carbondata.core.metadata.CarbonTableIdentifier in project carbondata by apache.

the class SegmentTaskIndexStoreTest method setUp.

@BeforeClass
public static void setUp() {
    CacheProvider cacheProvider = CacheProvider.getInstance();
    taskIndexStore = (SegmentTaskIndexStore) cacheProvider.<TableSegmentUniqueIdentifier, SegmentTaskIndexWrapper>createCache(CacheType.DRIVER_BTREE);
    tableBlockInfo = new TableBlockInfo("file", 0L, "SG100", locations, 10L, ColumnarFormatVersion.valueOf(version), null);
    absoluteTableIdentifier = AbsoluteTableIdentifier.from("/tmp", new CarbonTableIdentifier("testdatabase", "testtable", "TB100"));
}
Also used : TableBlockInfo(org.apache.carbondata.core.datastore.block.TableBlockInfo) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) SegmentTaskIndexWrapper(org.apache.carbondata.core.datastore.block.SegmentTaskIndexWrapper) CacheProvider(org.apache.carbondata.core.cache.CacheProvider) BeforeClass(org.junit.BeforeClass)

Example 48 with CarbonTableIdentifier

use of org.apache.carbondata.core.metadata.CarbonTableIdentifier in project carbondata by apache.

the class DictionaryCacheLoaderImplTest method setUp.

@BeforeClass
public static void setUp() {
    CarbonTableIdentifier carbonTableIdentifier = new CarbonTableIdentifier("db", "table1", "1");
    AbsoluteTableIdentifier absoluteTableIdentifier = AbsoluteTableIdentifier.from("/tmp", carbonTableIdentifier);
    Map<String, String> columnProperties = new HashMap<>();
    columnProperties.put("prop1", "value1");
    columnProperties.put("prop2", "value2");
    columnIdentifier = new ColumnIdentifier("1", columnProperties, DataTypes.STRING);
    dictionaryColumnUniqueIdentifier = new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier, columnIdentifier, columnIdentifier.getDataType());
    dictionaryCacheLoader = new DictionaryCacheLoaderImpl(dictionaryColumnUniqueIdentifier);
    dictionaryInfo = new ColumnDictionaryInfo(DataTypes.STRING);
    new MockUp<CarbonDictionaryReaderImpl>() {

        @Mock
        @SuppressWarnings("unused")
        Iterator<byte[]> read(long startOffset, long endOffset) throws IOException {
            ColumnDictionaryChunk columnDictionaryChunk = new ColumnDictionaryChunk();
            ByteBuffer byteBuffer1 = ByteBuffer.wrap("c".getBytes());
            ByteBuffer byteBuffer2 = ByteBuffer.wrap("d".getBytes());
            columnDictionaryChunk.setValues(Arrays.asList(byteBuffer1, byteBuffer2));
            return new ColumnDictionaryChunkIterator(Arrays.asList(columnDictionaryChunk));
        }
    };
    new MockUp<CarbonDictionarySortIndexReaderImpl>() {

        @Mock
        @SuppressWarnings("unused")
        List<Integer> readSortIndex() throws IOException {
            return Arrays.asList(1, 2);
        }

        @Mock
        @SuppressWarnings("unused")
        List<Integer> readInvertedSortIndex() throws IOException {
            return Arrays.asList(1, 2);
        }
    };
}
Also used : HashMap(java.util.HashMap) MockUp(mockit.MockUp) ByteBuffer(java.nio.ByteBuffer) ColumnDictionaryChunk(org.apache.carbondata.format.ColumnDictionaryChunk) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) BeforeClass(org.junit.BeforeClass)

Example 49 with CarbonTableIdentifier

use of org.apache.carbondata.core.metadata.CarbonTableIdentifier in project carbondata by apache.

the class DictionaryColumnUniqueIdentifierTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    CarbonTableIdentifier carbonTableIdentifier1 = new CarbonTableIdentifier("testDatabase", "testTable", "1");
    CarbonTableIdentifier carbonTableIdentifier2 = new CarbonTableIdentifier("testDatabase", "testTable", "2");
    AbsoluteTableIdentifier absoluteTableIdentifier1 = AbsoluteTableIdentifier.from("storepath", carbonTableIdentifier1);
    AbsoluteTableIdentifier absoluteTableIdentifier2 = AbsoluteTableIdentifier.from("storepath", carbonTableIdentifier2);
    Map<String, String> properties = new HashMap<>();
    ColumnIdentifier columnIdentifier = new ColumnIdentifier("2", properties, DataTypes.STRING);
    ColumnIdentifier columnIdentifier2 = new ColumnIdentifier("1", properties, DataTypes.INT);
    dictionaryColumnUniqueIdentifier1 = new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier1, columnIdentifier, DataTypes.STRING, null);
    dictionaryColumnUniqueIdentifier2 = new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier2, columnIdentifier2, DataTypes.STRING, null);
    dictionaryColumnUniqueIdentifier3 = new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier2, columnIdentifier, DataTypes.STRING, null);
}
Also used : CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) HashMap(java.util.HashMap) ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) BeforeClass(org.junit.BeforeClass)

Example 50 with CarbonTableIdentifier

use of org.apache.carbondata.core.metadata.CarbonTableIdentifier in project carbondata by apache.

the class CarbonTableReader method parseCarbonMetadata.

/**
 * Read the metadata of the given table and cache it in this.carbonCache (CarbonTableReader cache).
 *
 * @param table name of the given table.
 * @return the CarbonTable instance which contains all the needed metadata for a table.
 */
private CarbonTable parseCarbonMetadata(SchemaTableName table) {
    CarbonTable result = null;
    try {
        CarbonTableCacheModel cache = carbonCache.get().get(table);
        if (cache == null) {
            cache = new CarbonTableCacheModel();
        }
        if (cache.isValid())
            return cache.carbonTable;
        // If table is not previously cached, then:
        // Step 1: get store path of the table and cache it.
        // create table identifier. the table id is randomly generated.
        CarbonTableIdentifier carbonTableIdentifier = new CarbonTableIdentifier(table.getSchemaName(), table.getTableName(), UUID.randomUUID().toString());
        String storePath = config.getStorePath();
        String tablePath = storePath + "/" + carbonTableIdentifier.getDatabaseName() + "/" + carbonTableIdentifier.getTableName();
        // Step 2: read the metadata (tableInfo) of the table.
        ThriftReader.TBaseCreator createTBase = new ThriftReader.TBaseCreator() {

            // TBase is used to read and write thrift objects.
            // TableInfo is a kind of TBase used to read and write table information.
            // TableInfo is generated by thrift, see schema.thrift under format/src/main/thrift for details.
            public TBase create() {
                return new org.apache.carbondata.format.TableInfo();
            }
        };
        ThriftReader thriftReader = new ThriftReader(CarbonTablePath.getSchemaFilePath(tablePath), createTBase);
        thriftReader.open();
        org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
        thriftReader.close();
        // Step 3: convert format level TableInfo to code level TableInfo
        SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
        // wrapperTableInfo is the code level information of a table in carbondata core, different from the Thrift TableInfo.
        TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, table.getSchemaName(), table.getTableName(), tablePath);
        // Step 4: Load metadata info into CarbonMetadata
        CarbonMetadata.getInstance().loadTableMetadata(wrapperTableInfo);
        cache.carbonTable = CarbonMetadata.getInstance().getCarbonTable(table.getSchemaName(), table.getTableName());
        // cache the table
        carbonCache.get().put(table, cache);
        result = cache.carbonTable;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return result;
}
Also used : IOException(java.io.IOException) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) 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)

Aggregations

CarbonTableIdentifier (org.apache.carbondata.core.metadata.CarbonTableIdentifier)51 IOException (java.io.IOException)11 Test (org.junit.Test)11 AbsoluteTableIdentifier (org.apache.carbondata.core.metadata.AbsoluteTableIdentifier)10 ArrayList (java.util.ArrayList)9 ColumnIdentifier (org.apache.carbondata.core.metadata.ColumnIdentifier)7 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)6 File (java.io.File)5 DictionaryColumnUniqueIdentifier (org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 TableBlockInfo (org.apache.carbondata.core.datastore.block.TableBlockInfo)4 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)4 CarbonFactDataHandlerModel (org.apache.carbondata.processing.store.CarbonFactDataHandlerModel)4 CarbonFactHandler (org.apache.carbondata.processing.store.CarbonFactHandler)4 ExecutorService (java.util.concurrent.ExecutorService)3 AbstractIndex (org.apache.carbondata.core.datastore.block.AbstractIndex)3 TableBlockUniqueIdentifier (org.apache.carbondata.core.datastore.block.TableBlockUniqueIdentifier)3