Search in sources :

Example 6 with SourceTable

use of org.apache.hadoop.hive.metastore.api.SourceTable in project hive by apache.

the class TableBuilder method build.

public Table build(Configuration conf) throws MetaException {
    if (tableName == null) {
        throw new MetaException("You must set the table name");
    }
    if (ownerType == null) {
        ownerType = PrincipalType.USER;
    }
    if (owner == null) {
        try {
            owner = SecurityUtils.getUser();
        } catch (IOException e) {
            throw MetaStoreUtils.newMetaException(e);
        }
    }
    if (catName == null)
        catName = MetaStoreUtils.getDefaultCatalog(conf);
    Table t = new Table(tableName, dbName, owner, createTime, lastAccessTime, retention, buildSd(), partCols, tableParams, viewOriginalText, viewExpandedText, type);
    if (rewriteEnabled)
        t.setRewriteEnabled(true);
    if (temporary)
        t.setTemporary(temporary);
    t.setCatName(catName);
    if (!mvReferencedTables.isEmpty()) {
        Set<String> tablesUsed = mvReferencedTables.stream().map(sourceTable -> TableName.getDbTable(sourceTable.getTable().getDbName(), sourceTable.getTable().getTableName())).collect(Collectors.toSet());
        CreationMetadata cm = new CreationMetadata(catName, dbName, tableName, tablesUsed);
        cm.setSourceTables(mvReferencedTables);
        if (mvValidTxnList != null)
            cm.setValidTxnList(mvValidTxnList);
        t.setCreationMetadata(cm);
    }
    return t;
}
Also used : SecurityUtils(org.apache.hadoop.hive.metastore.utils.SecurityUtils) CreationMetadata(org.apache.hadoop.hive.metastore.api.CreationMetadata) MetaStoreUtils(org.apache.hadoop.hive.metastore.utils.MetaStoreUtils) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) TException(org.apache.thrift.TException) Set(java.util.Set) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Table(org.apache.hadoop.hive.metastore.api.Table) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) List(java.util.List) ValidTxnList(org.apache.hadoop.hive.common.ValidTxnList) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) TableType(org.apache.hadoop.hive.metastore.TableType) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) TableName(org.apache.hadoop.hive.common.TableName) Database(org.apache.hadoop.hive.metastore.api.Database) CreationMetadata(org.apache.hadoop.hive.metastore.api.CreationMetadata) Table(org.apache.hadoop.hive.metastore.api.Table) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) IOException(java.io.IOException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 7 with SourceTable

use of org.apache.hadoop.hive.metastore.api.SourceTable in project hive by apache.

the class TestHiveMetaStore method createMaterializedView.

private void createMaterializedView(String dbName, String tableName, Set<Table> tablesUsed) throws TException {
    Set<SourceTable> sourceTables = new HashSet<>(tablesUsed.size());
    for (Table table : tablesUsed) {
        sourceTables.add(createSourceTable(table));
    }
    Table t = new TableBuilder().setDbName(dbName).setTableName(tableName).setType(TableType.MATERIALIZED_VIEW.name()).addMaterializedViewReferencedTables(sourceTables).addCol("foo", "string").addCol("bar", "string").create(client, conf);
}
Also used : SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) Table(org.apache.hadoop.hive.metastore.api.Table) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) TableBuilder(org.apache.hadoop.hive.metastore.client.builder.TableBuilder) HashSet(java.util.HashSet)

Example 8 with SourceTable

use of org.apache.hadoop.hive.metastore.api.SourceTable in project hive by apache.

the class ObjectStore method convertToMCreationMetadata.

private MCreationMetadata convertToMCreationMetadata(CreationMetadata m) {
    if (m == null) {
        return null;
    }
    assert !m.isSetMaterializationTime();
    Set<MMVSource> tablesUsed = new HashSet<>();
    for (SourceTable sourceTable : m.getSourceTables()) {
        Table table = sourceTable.getTable();
        MTable mtbl = getMTable(m.getCatName(), table.getDbName(), table.getTableName(), false).mtbl;
        MMVSource source = new MMVSource();
        source.setTable(mtbl);
        source.setInsertedCount(sourceTable.getInsertedCount());
        source.setUpdatedCount(sourceTable.getUpdatedCount());
        source.setDeletedCount(sourceTable.getDeletedCount());
        tablesUsed.add(source);
    }
    return new MCreationMetadata(normalizeIdentifier(m.getCatName()), normalizeIdentifier(m.getDbName()), normalizeIdentifier(m.getTblName()), tablesUsed, m.getValidTxnList(), System.currentTimeMillis());
}
Also used : MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) Table(org.apache.hadoop.hive.metastore.api.Table) MTable(org.apache.hadoop.hive.metastore.model.MTable) MTable(org.apache.hadoop.hive.metastore.model.MTable) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) MMVSource(org.apache.hadoop.hive.metastore.model.MMVSource) HashSet(java.util.HashSet) MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata)

Example 9 with SourceTable

use of org.apache.hadoop.hive.metastore.api.SourceTable in project hive by apache.

the class HiveIncrementalRelMdRowCount method getRowCount.

@Override
public Double getRowCount(TableScan rel, RelMetadataQuery mq) {
    if (!(rel instanceof HiveTableScan)) {
        return super.getRowCount(rel, mq);
    }
    HiveTableScan tableScan = (HiveTableScan) rel;
    RelOptHiveTable relOptHiveTable = (RelOptHiveTable) tableScan.getTable();
    org.apache.hadoop.hive.ql.metadata.Table table = relOptHiveTable.getHiveTableMD();
    String fullyQualifiedName = TableName.getQualified(table.getCatName(), table.getDbName(), table.getTableName());
    SourceTable sourceTable = sourceTableMap.get(fullyQualifiedName);
    if (sourceTable == null) {
        return super.getRowCount(rel, mq);
    }
    return (double) sourceTable.getInsertedCount();
}
Also used : RelOptHiveTable(org.apache.hadoop.hive.ql.optimizer.calcite.RelOptHiveTable) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) HiveTableScan(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan)

Example 10 with SourceTable

use of org.apache.hadoop.hive.metastore.api.SourceTable in project hive by apache.

the class CreateMaterializedViewOperation method execute.

@Override
public int execute() throws HiveException {
    Table oldview = context.getDb().getTable(desc.getViewName(), false);
    if (oldview != null) {
        if (desc.getIfNotExists()) {
            return 0;
        }
        // Materialized View already exists, thus we should be replacing
        throw new HiveException(ErrorMsg.TABLE_ALREADY_EXISTS.getMsg(desc.getViewName()));
    } else {
        // We create new view
        Table tbl = desc.toTable(context.getConf());
        // We set the signature for the view if it is a materialized view
        if (tbl.isMaterializedView()) {
            Set<SourceTable> sourceTables = new HashSet<>(desc.getTablesUsed().size());
            for (TableName tableName : desc.getTablesUsed()) {
                sourceTables.add(context.getDb().getTable(tableName).createSourceTable());
            }
            MaterializedViewMetadata metadata = new MaterializedViewMetadata(MetaStoreUtils.getDefaultCatalog(context.getConf()), tbl.getDbName(), tbl.getTableName(), sourceTables, context.getConf().get(ValidTxnWriteIdList.VALID_TABLES_WRITEIDS_KEY));
            tbl.setMaterializedViewMetadata(metadata);
        }
        context.getDb().createTable(tbl, desc.getIfNotExists());
        DDLUtils.addIfAbsentByName(new WriteEntity(tbl, WriteEntity.WriteType.DDL_NO_LOCK), context.getWork().getOutputs());
        // set lineage info
        DataContainer dc = new DataContainer(tbl.getTTable());
        Map<String, String> tblProps = tbl.getTTable().getParameters();
        Path tlocation = null;
        try {
            Warehouse wh = new Warehouse(context.getConf());
            tlocation = wh.getDefaultTablePath(context.getDb().getDatabase(tbl.getDbName()), tbl.getTableName(), tblProps == null || !AcidUtils.isTablePropertyTransactional(tblProps));
        } catch (MetaException e) {
            throw new HiveException(e);
        }
        context.getQueryState().getLineageState().setLineage(tlocation, dc, tbl.getCols());
    }
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) Table(org.apache.hadoop.hive.ql.metadata.Table) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) TableName(org.apache.hadoop.hive.common.TableName) DataContainer(org.apache.hadoop.hive.ql.hooks.LineageInfo.DataContainer) MaterializedViewMetadata(org.apache.hadoop.hive.ql.metadata.MaterializedViewMetadata) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) HashSet(java.util.HashSet) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

SourceTable (org.apache.hadoop.hive.metastore.api.SourceTable)18 Table (org.apache.hadoop.hive.metastore.api.Table)8 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)6 TableName (org.apache.hadoop.hive.common.TableName)4 CreationMetadata (org.apache.hadoop.hive.metastore.api.CreationMetadata)4 Table (org.apache.hadoop.hive.ql.metadata.Table)4 HashMap (java.util.HashMap)3 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ValidTxnWriteIdList (org.apache.hadoop.hive.common.ValidTxnWriteIdList)2 TableType (org.apache.hadoop.hive.metastore.TableType)2 Warehouse (org.apache.hadoop.hive.metastore.Warehouse)2 Materialization (org.apache.hadoop.hive.metastore.api.Materialization)2 MTable (org.apache.hadoop.hive.metastore.model.MTable)2 MVersionTable (org.apache.hadoop.hive.metastore.model.MVersionTable)2