Search in sources :

Example 1 with TableInfo

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

the class ThriftWrapperSchemaConverterImpl method fromExternalToWrapperTableInfo.

/* (non-Javadoc)
   * convert from external to wrapper tableinfo
   */
@Override
public TableInfo fromExternalToWrapperTableInfo(org.apache.carbondata.format.TableInfo externalTableInfo, String dbName, String tableName, String storePath) {
    TableInfo wrapperTableInfo = new TableInfo();
    List<org.apache.carbondata.format.SchemaEvolutionEntry> schemaEvolutionList = externalTableInfo.getFact_table().getSchema_evolution().getSchema_evolution_history();
    wrapperTableInfo.setLastUpdatedTime(schemaEvolutionList.get(schemaEvolutionList.size() - 1).getTime_stamp());
    wrapperTableInfo.setDatabaseName(dbName);
    wrapperTableInfo.setTableUniqueName(dbName + "_" + tableName);
    wrapperTableInfo.setStorePath(storePath);
    wrapperTableInfo.setFactTable(fromExternalToWrapperTableSchema(externalTableInfo.getFact_table(), tableName));
    List<TableSchema> aggTablesList = new ArrayList<TableSchema>();
    int index = 0;
    for (org.apache.carbondata.format.TableSchema aggTable : externalTableInfo.getAggregate_table_list()) {
        aggTablesList.add(fromExternalToWrapperTableSchema(aggTable, "agg_table_" + index));
        index++;
    }
    return wrapperTableInfo;
}
Also used : SchemaEvolutionEntry(org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry) TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ArrayList(java.util.ArrayList) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo)

Example 2 with TableInfo

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

the class DictionaryClientTest 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);
    // Start the server for testing the client
    server = DictionaryServer.getInstance(5678);
}
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 3 with TableInfo

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

the class ThriftWrapperSchemaConverterImplTest method testFromWrapperToExternalTableInfo.

@Test
public void testFromWrapperToExternalTableInfo() {
    TableInfo wrapperTableInfo = new TableInfo();
    String dbName = "dbName";
    String tableName = "TableName";
    final TableSchema wrapperTableSchema = new TableSchema();
    final List<TableSchema> tableSchemas = new ArrayList<>();
    tableSchemas.add(wrapperTableSchema);
    new MockUp<SchemaEvolutionEntry>() {

        @Mock
        public List<ColumnSchema> getAdded() {
            return columnSchemas;
        }

        @Mock
        public List<ColumnSchema> getRemoved() {
            return columnSchemas;
        }
    };
    new MockUp<ColumnSchema>() {

        @Mock
        public List<Encoding> getEncodingList() {
            return encodings;
        }

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

        @Mock
        public DataType getDataType() {
            return DataType.BOOLEAN;
        }

        @Mock
        public String getColumnName() {
            return "columnName";
        }

        @Mock
        public String getColumnUniqueId() {
            return "1";
        }

        @Mock
        public boolean isColumnar() {
            return true;
        }

        @Mock
        public boolean isDimensionColumn() {
            return true;
        }

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

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

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

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

        @Mock
        public byte[] getDefaultValue() {
            return new byte[] { 1, 2 };
        }

        @Mock
        public Map<String, String> getColumnProperties() {
            return columnPropertyMap;
        }

        @Mock
        public boolean isInvisible() {
            return true;
        }

        @Mock
        public String getColumnReferenceId() {
            return "1";
        }
    };
    new MockUp<TableInfo>() {

        @Mock
        public TableSchema getFactTable() {
            return wrapperTableSchema;
        }

        @Mock
        public List<TableSchema> getAggregateTableList() {
            return tableSchemas;
        }
    };
    new MockUp<TableSchema>() {

        @Mock
        public List<ColumnSchema> getListOfColumns() {
            return columnSchemas;
        }

        final SchemaEvolution schemaEvolution = new SchemaEvolution();

        final Map mapTableProperties = new HashMap<String, String>();

        @Mock
        public SchemaEvolution getSchemaEvalution() {
            return schemaEvolution;
        }

        @Mock
        public String getTableId() {
            return "tableId";
        }

        @Mock
        public Map<String, String> getTableProperties() {
            return mapTableProperties;
        }
    };
    org.apache.carbondata.format.TableSchema thriftFactTable = new org.apache.carbondata.format.TableSchema("tableId", thriftColumnSchemas, schemaEvol);
    List<org.apache.carbondata.format.TableSchema> thriftAggTables = new ArrayList<>();
    thriftAggTables.add(thriftFactTable);
    org.apache.carbondata.format.TableInfo actualResult = thriftWrapperSchemaConverter.fromWrapperToExternalTableInfo(wrapperTableInfo, dbName, tableName);
    org.apache.carbondata.format.TableInfo expectedResult = new org.apache.carbondata.format.TableInfo(thriftFactTable, thriftAggTables);
    assertEquals(expectedResult, actualResult);
}
Also used : TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) Encoding(org.apache.carbondata.core.metadata.encoder.Encoding) SchemaEvolution(org.apache.carbondata.core.metadata.schema.SchemaEvolution) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with TableInfo

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

the class CarbonMetadataTest method getTableInfo.

private static TableInfo getTableInfo(long timeStamp) {
    TableInfo info = new TableInfo();
    info.setDatabaseName("carbonTestDatabase");
    info.setLastUpdatedTime(timeStamp);
    info.setTableUniqueName("carbonTestDatabase_carbonTestTable");
    info.setFactTable(getTableSchema());
    info.setStorePath("/test/store");
    return info;
}
Also used : TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo)

Example 5 with TableInfo

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

the class SchemaReader method readCarbonTableFromStore.

public static CarbonTable readCarbonTableFromStore(AbsoluteTableIdentifier identifier) throws IOException {
    CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(identifier);
    String schemaFilePath = carbonTablePath.getSchemaFilePath();
    if (FileFactory.isFileExist(schemaFilePath, FileFactory.FileType.LOCAL) || FileFactory.isFileExist(schemaFilePath, FileFactory.FileType.HDFS) || FileFactory.isFileExist(schemaFilePath, FileFactory.FileType.VIEWFS)) {
        String tableName = identifier.getCarbonTableIdentifier().getTableName();
        ThriftReader.TBaseCreator createTBase = new ThriftReader.TBaseCreator() {

            public TBase create() {
                return new org.apache.carbondata.format.TableInfo();
            }
        };
        ThriftReader thriftReader = new ThriftReader(carbonTablePath.getSchemaFilePath(), createTBase);
        thriftReader.open();
        org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
        thriftReader.close();
        SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
        TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, identifier.getCarbonTableIdentifier().getDatabaseName(), tableName, identifier.getStorePath());
        wrapperTableInfo.setMetaDataFilepath(CarbonTablePath.getFolderContainingFile(schemaFilePath));
        CarbonMetadata.getInstance().loadTableMetadata(wrapperTableInfo);
        return CarbonMetadata.getInstance().getCarbonTable(identifier.getCarbonTableIdentifier().getTableUniqueName());
    } else {
        throw new IOException("File does not exist: " + schemaFilePath);
    }
}
Also used : IOException(java.io.IOException) ThriftReader(org.apache.carbondata.core.reader.ThriftReader) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) 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

TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)13 TableSchema (org.apache.carbondata.core.metadata.schema.table.TableSchema)10 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)7 ArrayList (java.util.ArrayList)6 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)5 CarbonMetadata (org.apache.carbondata.core.metadata.CarbonMetadata)4 SchemaConverter (org.apache.carbondata.core.metadata.converter.SchemaConverter)4 ThriftWrapperSchemaConverterImpl (org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl)4 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)4 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)3 SchemaEvolution (org.apache.carbondata.core.metadata.schema.SchemaEvolution)3 SchemaEvolutionEntry (org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry)3 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)3 Before (org.junit.Before)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 MockUp (mockit.MockUp)2 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)2 ThriftReader (org.apache.carbondata.core.reader.ThriftReader)2 ThriftWriter (org.apache.carbondata.core.writer.ThriftWriter)2