Search in sources :

Example 1 with MMVSource

use of org.apache.hadoop.hive.metastore.model.MMVSource 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 2 with MMVSource

use of org.apache.hadoop.hive.metastore.model.MMVSource in project hive by apache.

the class ObjectStore method convertToCreationMetadata.

private CreationMetadata convertToCreationMetadata(MCreationMetadata s) throws MetaException {
    if (s == null) {
        return null;
    }
    Set<String> tablesUsed = new HashSet<>();
    List<SourceTable> sourceTables = new ArrayList<>(s.getTables().size());
    for (MMVSource mtbl : s.getTables()) {
        tablesUsed.add(Warehouse.getQualifiedName(mtbl.getTable().getDatabase().getName(), mtbl.getTable().getTableName()));
        sourceTables.add(convertToSourceTable(mtbl, s.getCatalogName()));
    }
    CreationMetadata r = new CreationMetadata(s.getCatalogName(), s.getDbName(), s.getTblName(), tablesUsed);
    r.setMaterializationTime(s.getMaterializationTime());
    if (s.getTxnList() != null) {
        r.setValidTxnList(s.getTxnList());
    }
    r.setSourceTables(sourceTables);
    return r;
}
Also used : MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata) CreationMetadata(org.apache.hadoop.hive.metastore.api.CreationMetadata) ArrayList(java.util.ArrayList) SourceTable(org.apache.hadoop.hive.metastore.api.SourceTable) MMVSource(org.apache.hadoop.hive.metastore.model.MMVSource) HashSet(java.util.HashSet)

Example 3 with MMVSource

use of org.apache.hadoop.hive.metastore.model.MMVSource in project hive by apache.

the class ObjectStore method isPartOfMaterializedView.

@Override
public List<String> isPartOfMaterializedView(String catName, String dbName, String tblName) {
    boolean committed = false;
    Query query = null;
    List<String> mViewList = new ArrayList<>();
    try {
        openTransaction();
        query = pm.newQuery("select from org.apache.hadoop.hive.metastore.model.MCreationMetadata");
        List<MCreationMetadata> creationMetadata = (List<MCreationMetadata>) query.execute();
        Iterator<MCreationMetadata> iter = creationMetadata.iterator();
        while (iter.hasNext()) {
            MCreationMetadata p = iter.next();
            Set<MMVSource> tables = p.getTables();
            for (MMVSource sourceTable : tables) {
                MTable table = sourceTable.getTable();
                if (dbName.equals(table.getDatabase().getName()) && tblName.equals(table.getTableName())) {
                    LOG.info("Cannot drop table " + table.getTableName() + " as it is being used by MView " + p.getTblName());
                    mViewList.add(p.getDbName() + "." + p.getTblName());
                }
            }
        }
        committed = commitTransaction();
    } finally {
        rollbackAndCleanup(committed, query);
    }
    return mViewList;
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) ArrayList(java.util.ArrayList) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MMVSource(org.apache.hadoop.hive.metastore.model.MMVSource) MCreationMetadata(org.apache.hadoop.hive.metastore.model.MCreationMetadata)

Aggregations

MCreationMetadata (org.apache.hadoop.hive.metastore.model.MCreationMetadata)3 MMVSource (org.apache.hadoop.hive.metastore.model.MMVSource)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 SourceTable (org.apache.hadoop.hive.metastore.api.SourceTable)2 MTable (org.apache.hadoop.hive.metastore.model.MTable)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Query (javax.jdo.Query)1 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)1 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)1 CreationMetadata (org.apache.hadoop.hive.metastore.api.CreationMetadata)1 ReplicationMetricList (org.apache.hadoop.hive.metastore.api.ReplicationMetricList)1 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)1 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)1 MVersionTable (org.apache.hadoop.hive.metastore.model.MVersionTable)1