@Override public String toString() { return Warehouse.getQualifiedName(table) + "(" + alias + ")"; }
public String getFullyQualifiedName() { return Warehouse.getQualifiedName(tTable); }
protected String tableName(Table t) { return Warehouse.getQualifiedName(t); }
/** * Releases a certain lock. * @param dbName the db name of the materialization * @param tableName the table name of the materialization * @param txnId the transaction id for the rebuild * @return true if the lock could be released properly, false otherwise * @throws MetaException */ public boolean unlockResource(String dbName, String tableName, long txnId) { final String fullyQualifiedName = Warehouse.getQualifiedName(dbName, tableName); final ResourceLock prevResourceLock = locks.get(fullyQualifiedName); if (prevResourceLock == null || prevResourceLock.txnId != txnId) { return false; } return locks.remove(fullyQualifiedName, prevResourceLock); }
/** * @param dbName actual database name * @param tblName actual table name or search pattern (for error message) */ public static Map<String, Table> getTempTablesForDatabase(String dbName, String tblName) { return getTempTables(Warehouse.getQualifiedName(dbName, tblName)). get(dbName); }
/** * Moves from ACQUIRED state to COMMIT_READY. * @param dbName the db name of the materialization * @param tableName the table name of the materialization * @param txnId the transaction id for the rebuild * @return true if the lock was still active and we could move the materialization * to COMMIT_READY state, false otherwise */ public boolean readyToCommitResource(String dbName, String tableName, long txnId) { final ResourceLock prevResourceLock = locks.get(Warehouse.getQualifiedName(dbName, tableName)); if (prevResourceLock == null || prevResourceLock.txnId != txnId) { // Lock was outdated and it was removed (then maybe another transaction picked it up) return false; } return prevResourceLock.state.compareAndSet(State.ACQUIRED, State.COMMIT_READY); }
private static String getTmptTableNameForExport(Table exportTable) { String tmpTableDb = exportTable.getDbName(); String tmpTableName = exportTable.getTableName() + "_" + UUID.randomUUID().toString().replace('-', '_'); return Warehouse.getQualifiedName(tmpTableDb, tmpTableName); }
private static void removeTempTable(org.apache.hadoop.hive.metastore.api.Table t) { String qualifiedTableName = Warehouse. getQualifiedName(t.getDbName().toLowerCase(), t.getTableName().toLowerCase()); SessionState ss = SessionState.get(); if (ss == null) { LOG.warn("No current SessionState, skipping temp partitions for " + qualifiedTableName); return; } ss.getTempPartitions().remove(Warehouse.getQualifiedName(t)); } private static void createTempTable(org.apache.hadoop.hive.metastore.api.Table t) {
private Map<String, ColumnStatisticsObj> getTempTableColumnStatsForTable(String dbName, String tableName) { SessionState ss = SessionState.get(); if (ss == null) { LOG.debug("No current SessionState, skipping temp tables for " + Warehouse.getQualifiedName(dbName, tableName)); return null; } String lookupName = StatsUtils.getFullyQualifiedTableName(dbName.toLowerCase(), tableName.toLowerCase()); return ss.getTempTableColStats().get(lookupName); }
private static boolean isFullAcidTable(Table t) { if (t.getParametersSize() <= 0) { //cannot be acid return false; } String transacationalValue = t.getParameters() .get(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL); if (transacationalValue != null && "true".equalsIgnoreCase(transacationalValue)) { System.out.println("Found Acid table: " + Warehouse.getQualifiedName(t)); return true; } return false; } private static boolean isAcidEnabled(HiveConf hiveConf) {
private static boolean isFullAcidTable(Table t) { if (t.getParametersSize() <= 0) { //cannot be acid return false; } String transacationalValue = t.getParameters() .get(hive_metastoreConstants.TABLE_IS_TRANSACTIONAL); if (transacationalValue != null && "true".equalsIgnoreCase(transacationalValue)) { System.out.println("Found Acid table: " + Warehouse.getQualifiedName(t)); return true; } return false; } private static boolean isAcidEnabled(HiveConf hiveConf) {
public TruncateTableDesc(String tableName, Map<String, String> partSpec, ReplicationSpec replicationSpec, Table table) { this.tableName = tableName; this.partSpec = partSpec; this.replicationSpec = replicationSpec; this.isTransactional = AcidUtils.isTransactionalTable(table); this.fullTableName = table == null ? tableName : Warehouse.getQualifiedName(table.getTTable()); }
private static String getCompactionCommand(Table t, Partition p) { StringBuilder sb = new StringBuilder("ALTER TABLE ").append(Warehouse.getQualifiedName(t)); if(t.getPartitionKeysSize() > 0) { assert p != null : "must supply partition for partitioned table " + Warehouse.getQualifiedName(t); sb.append(" PARTITION("); for (int i = 0; i < t.getPartitionKeysSize(); i++) { sb.append(t.getPartitionKeys().get(i).getName()).append('=').append( genPartValueString(t.getPartitionKeys().get(i).getType(), p.getValues().get(i))). append(","); } sb.setCharAt(sb.length() - 1, ')');//replace trailing ',' } return sb.append(" COMPACT 'major'").toString(); }
private void assertPartitioned() throws MetaException { if(tTable.getPartitionKeysSize() <= 0) { throw new MetaException(Warehouse.getQualifiedName(tTable) + " is not partitioned"); } }
private static TempTable getTempTable(org.apache.hadoop.hive.metastore.api.Table t) { String qualifiedTableName = Warehouse. getQualifiedName(t.getDbName().toLowerCase(), t.getTableName().toLowerCase()); SessionState ss = SessionState.get(); if (ss == null) { LOG.warn("No current SessionState, skipping temp partitions for " + qualifiedTableName); return null; } return ss.getTempPartitions().get(qualifiedTableName); } private static void removeTempTable(org.apache.hadoop.hive.metastore.api.Table t) {
/** * Lock materialized view (first step for rebuild). Response contains a lock id * that corresponds to the input transaction id, and whether the lock was * ACQUIRED or NOT_ACQUIRED. * @param dbName the db name of the materialization * @param tableName the table name of the materialization * @param txnId the transaction id for the rebuild * @return the response to the lock request */ public LockResponse lockResource(String dbName, String tableName, long txnId) { final ResourceLock prevResourceLock = locks.putIfAbsent( Warehouse.getQualifiedName(dbName, tableName), new ResourceLock(txnId, System.nanoTime(), State.ACQUIRED)); if (prevResourceLock != null) { return new LockResponse(txnId, LockState.NOT_ACQUIRED); } return new LockResponse(txnId, LockState.ACQUIRED); }
private static void createTempTable(org.apache.hadoop.hive.metastore.api.Table t) { if(t.getPartitionKeysSize() <= 0) { //do nothing as it's not a partitioned table return; } String qualifiedTableName = Warehouse. getQualifiedName(t.getDbName().toLowerCase(), t.getTableName().toLowerCase()); SessionState ss = SessionState.get(); if (ss == null) { LOG.warn("No current SessionState, skipping temp partitions for " + qualifiedTableName); return; } TempTable tt = new TempTable(t); if(ss.getTempPartitions().putIfAbsent(qualifiedTableName, tt) != null) { throw new IllegalStateException("TempTable for " + qualifiedTableName + " already exists"); } } }
private void checkSorted(Table newTable) throws MetaException { if(!TxnUtils.isAcidTable(newTable)) { return; } StorageDescriptor sd = newTable.getSd(); if (sd.getSortCols() != null && sd.getSortCols().size() > 0) { throw new MetaException("Table " + Warehouse.getQualifiedName(newTable) + " cannot support full ACID functionality since it is sorted."); } }
@Override public String toString() { return isPartition() ? StatsUtils.getFullyQualifiedTableName(part.getDbName(), part.getTableName()) + "@" + part.getValues() : Warehouse.getQualifiedName(tab); } }
private static Table createNewTableMetadataObject(ImportTableDesc tblDesc, boolean isRepl) throws SemanticException { Table newTable = new Table(tblDesc.getDatabaseName(), tblDesc.getTableName()); //so that we know the type of table we are creating: acid/MM to match what was exported newTable.setParameters(tblDesc.getTblProps()); if(tblDesc.isExternal() && AcidUtils.isTransactionalTable(newTable)) { if (isRepl) { throw new SemanticException("External tables may not be transactional: " + Warehouse.getQualifiedName(tblDesc.getDatabaseName(), tblDesc.getTableName())); } else { throw new AssertionError("Internal error: transactional properties not set properly" + tblDesc.getTblProps()); } } return newTable; }