use of org.apache.flink.table.catalog.ObjectPath in project flink by apache.
the class TpcdsTestProgram method prepareTableEnv.
/**
* Prepare TableEnvironment for query.
*
* @param sourceTablePath
* @return
*/
private static TableEnvironment prepareTableEnv(String sourceTablePath, Boolean useTableStats) {
// init Table Env
EnvironmentSettings environmentSettings = EnvironmentSettings.inBatchMode();
TableEnvironment tEnv = TableEnvironment.create(environmentSettings);
// config Optimizer parameters
// TODO use the default shuffle mode of batch runtime mode once FLINK-23470 is implemented
tEnv.getConfig().getConfiguration().setString(ExecutionConfigOptions.TABLE_EXEC_SHUFFLE_MODE, GlobalStreamExchangeMode.POINTWISE_EDGES_PIPELINED.toString());
tEnv.getConfig().getConfiguration().setLong(OptimizerConfigOptions.TABLE_OPTIMIZER_BROADCAST_JOIN_THRESHOLD, 10 * 1024 * 1024);
tEnv.getConfig().getConfiguration().setBoolean(OptimizerConfigOptions.TABLE_OPTIMIZER_JOIN_REORDER_ENABLED, true);
// register TPC-DS tables
TPCDS_TABLES.forEach(table -> {
TpcdsSchema schema = TpcdsSchemaProvider.getTableSchema(table);
CsvTableSource.Builder builder = CsvTableSource.builder();
builder.path(sourceTablePath + FILE_SEPARATOR + table + DATA_SUFFIX);
for (int i = 0; i < schema.getFieldNames().size(); i++) {
builder.field(schema.getFieldNames().get(i), TypeConversions.fromDataTypeToLegacyInfo(schema.getFieldTypes().get(i)));
}
builder.fieldDelimiter(COL_DELIMITER);
builder.emptyColumnAsNull();
builder.lineDelimiter("\n");
CsvTableSource tableSource = builder.build();
ConnectorCatalogTable catalogTable = ConnectorCatalogTable.source(tableSource, true);
tEnv.getCatalog(tEnv.getCurrentCatalog()).ifPresent(catalog -> {
try {
catalog.createTable(new ObjectPath(tEnv.getCurrentDatabase(), table), catalogTable, false);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
});
// register statistics info
if (useTableStats) {
TpcdsStatsProvider.registerTpcdsStats(tEnv);
}
return tEnv;
}
use of org.apache.flink.table.catalog.ObjectPath in project flink by apache.
the class HiveCatalog method instantiateHivePartition.
private Partition instantiateHivePartition(Table hiveTable, CatalogPartitionSpec partitionSpec, CatalogPartition catalogPartition) throws PartitionSpecInvalidException {
List<String> partCols = getFieldNames(hiveTable.getPartitionKeys());
List<String> partValues = getOrderedFullPartitionValues(partitionSpec, partCols, new ObjectPath(hiveTable.getDbName(), hiveTable.getTableName()));
// validate partition values
for (int i = 0; i < partCols.size(); i++) {
if (isNullOrWhitespaceOnly(partValues.get(i))) {
throw new PartitionSpecInvalidException(getName(), partCols, new ObjectPath(hiveTable.getDbName(), hiveTable.getTableName()), partitionSpec);
}
}
// TODO: handle GenericCatalogPartition
StorageDescriptor sd = hiveTable.getSd().deepCopy();
sd.setLocation(catalogPartition.getProperties().remove(SqlCreateHiveTable.TABLE_LOCATION_URI));
Map<String, String> properties = new HashMap<>(catalogPartition.getProperties());
String comment = catalogPartition.getComment();
if (comment != null) {
properties.put(HiveCatalogConfig.COMMENT, comment);
}
return HiveTableUtil.createHivePartition(hiveTable.getDbName(), hiveTable.getTableName(), partValues, sd, properties);
}
use of org.apache.flink.table.catalog.ObjectPath in project flink by apache.
the class MySqlCatalogITCase method testGetTables_TableNotExistException_NoDb.
@Test
public void testGetTables_TableNotExistException_NoDb() throws TableNotExistException {
String databaseNotExist = "nonexistdb";
String tableNotExist = "anyTable";
assertThatThrownBy(() -> catalog.getTable(new ObjectPath(databaseNotExist, tableNotExist))).satisfies(anyCauseMatches(TableNotExistException.class, String.format("Table (or view) %s.%s does not exist in Catalog", databaseNotExist, tableNotExist)));
}
use of org.apache.flink.table.catalog.ObjectPath in project flink by apache.
the class PostgresCatalogTest method testPrimitiveDataTypes.
@Test
public void testPrimitiveDataTypes() throws TableNotExistException {
CatalogBaseTable table = catalog.getTable(new ObjectPath(PostgresCatalog.DEFAULT_DATABASE, TABLE_PRIMITIVE_TYPE));
assertEquals(getPrimitiveTable().schema, table.getUnresolvedSchema());
}
use of org.apache.flink.table.catalog.ObjectPath in project flink by apache.
the class PostgresCatalogTest method testGetTables_TableNotExistException_NoSchema.
@Test
public void testGetTables_TableNotExistException_NoSchema() throws TableNotExistException {
exception.expect(TableNotExistException.class);
catalog.getTable(new ObjectPath(TEST_DB, PostgresTablePath.toFlinkTableName("nonexistschema", "anytable")));
}
Aggregations