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;
}
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);
}
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());
}
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();
}
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;
}
Aggregations