@Override public ExternalCatalogTable getTable(String tableName) throws TableNotExistException { MockExternalCatalogTable table = tables.get(tableName); if (table == null) { throw new TableNotExistException(database, "Table " + tableName + " does not exist"); } return table.toExternalCatalogTable(); }
@Override public ExternalCatalogTable getTable(String tableName) throws TableNotExistException { if (!tables.containsKey(tableName)) { throw new TableNotExistException(CATALOG_NAME_DEFAULT, tableName); } return tables.get(tableName); }
@Override public void dropTable(ObjectPath tableName, boolean ignoreIfNotExists) throws TableNotExistException { if (tableExists(tableName)) { tables.remove(tableName); } else if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, tableName.getFullName()); } }
@Override public CatalogTable getTable(ObjectPath tableName) throws TableNotExistException { if (!tableExists(tableName)) { throw new TableNotExistException(catalogName, tableName.getFullName()); } else { return tables.get(tableName); } }
@Override public void alterTable(ObjectPath tableName, CatalogTable newTable, boolean ignoreIfNotExists) throws TableNotExistException { if (tableExists(tableName)) { tables.put(tableName, newTable); } else if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, tableName.getFullName()); } }
@Override public void renameTable(ObjectPath tableName, String newTableName, boolean ignoreIfNotExists) throws TableNotExistException, DatabaseNotExistException { if (tableExists(tableName)) { tables.put(new ObjectPath(tableName.getDbName(), newTableName), tables.remove(tableName)); } else if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, tableName.getFullName()); } }
@Override public TableStats getTableStats(ObjectPath path) throws TableNotExistException { if (!tableExists(path)) { throw new TableNotExistException(catalogName, path.getFullName()); } else { if (!isTablePartitioned(path)) { return tables.get(path).getTableStats(); } else { return new TableStats(); } } }
@Override public void dropPartition(ObjectPath path, CatalogPartition.PartitionSpec partitionSpec, boolean ignoreIfNotExists) throws TableNotExistException, TableNotPartitionedException, PartitionNotExistException { if (!tableExists(path)) { throw new TableNotExistException(catalogName, path.getFullName()); } if (!isTablePartitioned(path)) { throw new TableNotPartitionedException(catalogName, path); } if (partitionExists(path, partitionSpec)) { partitions.get(path).remove(partitionSpec); } else if (!ignoreIfNotExists) { throw new PartitionNotExistException(catalogName, path, partitionSpec); } }
private Table getHiveTable(ObjectPath path) throws TableNotExistException { try { return client.getTable(path.getDbName(), path.getObjectName()); } catch (NoSuchObjectException e) { throw new TableNotExistException(catalogName, path.getFullName()); } catch (TException e) { throw new FlinkHiveException( String.format("Failed to get table %s", path.getFullName()), e); } }
@Override public void dropTable(ObjectPath path, boolean ignoreIfNotExists) throws TableNotExistException { try { client.dropTable(path.getDbName(), path.getObjectName(), true, ignoreIfNotExists); } catch (NoSuchObjectException e) { if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, path.getFullName()); } } catch (TException e) { throw new FlinkHiveException( String.format("Failed to drop table %s", path.getFullName()), e); } }
@Override public void alterPartition(ObjectPath path, CatalogPartition newPartition, boolean ignoreIfNotExists) throws TableNotExistException, TableNotPartitionedException, PartitionNotExistException { if (!tableExists(path)) { throw new TableNotExistException(catalogName, path.getFullName()); } if (!isTablePartitioned(path)) { throw new TableNotPartitionedException(catalogName, path); } CatalogPartition.PartitionSpec partitionSpec = newPartition.getPartitionSpec(); if (partitionExists(path, partitionSpec)) { partitions.get(path).put(partitionSpec, newPartition); } else if (!ignoreIfNotExists) { throw new PartitionNotExistException(catalogName, path, partitionSpec); } }
@Override public void alterTable(ObjectPath path, CatalogTable newTable, boolean ignoreIfNotExists) throws TableNotExistException { try { if (tableExists(path)) { client.alter_table(path.getDbName(), path.getObjectName(), HiveMetadataUtil.createHiveTable(path, newTable)); } else if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, path.getFullName()); } } catch (TException e) { throw new FlinkHiveException( String.format("Failed to alter table %s", path.getFullName()), e); } }
@Override public void createPartition(ObjectPath path, CatalogPartition partition, boolean ignoreIfExists) throws TableNotExistException, TableNotPartitionedException, PartitionAlreadyExistException { if (!tableExists(path)) { throw new TableNotExistException(catalogName, path.getFullName()); } if (!isTablePartitioned(path)) { throw new TableNotPartitionedException(catalogName, path); } if (partitionExists(path, partition.getPartitionSpec())) { if (!ignoreIfExists) { throw new PartitionAlreadyExistException(catalogName, path, partition.getPartitionSpec()); } } else { partitions.get(path).put(partition.getPartitionSpec(), partition); } }
@Override public void alterTableStats(ObjectPath path, TableStats newtTableStats, boolean ignoreIfNotExists) throws TableNotExistException { try { Table hiveTable = getHiveTable(path); // Set table column stats. This only works for non-partitioned tables. if (!isTablePartitioned(hiveTable)) { client.updateTableColumnStatistics(HiveMetadataUtil.createColumnStats(hiveTable, newtTableStats.colStats())); } // Set table stats String oldRowCount = hiveTable.getParameters().getOrDefault(StatsSetupConst.ROW_COUNT, "0"); if (newtTableStats.rowCount() != Long.parseLong(oldRowCount)) { hiveTable.getParameters().put(StatsSetupConst.ROW_COUNT, String.valueOf(newtTableStats.rowCount())); client.alter_table(path.getDbName(), path.getObjectName(), hiveTable); } } catch (TableNotExistException e) { if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, path.getFullName()); } } catch (TException e) { throw new FlinkHiveException( String.format("Failed to alter table stats of table %s", path.getFullName()), e); } }
@Override public void alterTableStats(ObjectPath tablePath, TableStats newtTableStats, boolean ignoreIfNotExists) throws TableNotExistException { if (tableExists(tablePath)) { if (!isTablePartitioned(tablePath)) { CatalogTable oldTable = tables.get(tablePath); tables.put(tablePath, new CatalogTable( oldTable.getTableType(), oldTable.getTableSchema(), oldTable.getProperties(), oldTable.getRichTableSchema(), newtTableStats, oldTable.getComment(), oldTable.getPartitionColumnNames(), oldTable.isPartitioned(), oldTable.getComputedColumns(), oldTable.getRowTimeField(), oldTable.getWatermarkOffset(), oldTable.getCreateTime(), oldTable.getLastAccessTime(), oldTable.isStreaming() )); } } else if (!ignoreIfNotExists) { throw new TableNotExistException(catalogName, tablePath.getFullName()); } }