Search in sources :

Example 21 with ObjectPath

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;
}
Also used : EnvironmentSettings(org.apache.flink.table.api.EnvironmentSettings) ObjectPath(org.apache.flink.table.catalog.ObjectPath) ConnectorCatalogTable(org.apache.flink.table.catalog.ConnectorCatalogTable) CsvTableSource(org.apache.flink.table.sources.CsvTableSource) TableEnvironment(org.apache.flink.table.api.TableEnvironment) TpcdsSchema(org.apache.flink.table.tpcds.schema.TpcdsSchema)

Example 22 with ObjectPath

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);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) HashMap(java.util.HashMap) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) UniqueConstraint(org.apache.flink.table.api.constraints.UniqueConstraint) PartitionSpecInvalidException(org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException)

Example 23 with ObjectPath

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)));
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) Test(org.junit.Test)

Example 24 with ObjectPath

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());
}
Also used : CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) ObjectPath(org.apache.flink.table.catalog.ObjectPath) Test(org.junit.Test)

Example 25 with ObjectPath

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")));
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) Test(org.junit.Test)

Aggregations

ObjectPath (org.apache.flink.table.catalog.ObjectPath)81 Test (org.junit.Test)52 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)32 CatalogTable (org.apache.flink.table.catalog.CatalogTable)29 HashMap (java.util.HashMap)21 CatalogTableImpl (org.apache.flink.table.catalog.CatalogTableImpl)20 TableSchema (org.apache.flink.table.api.TableSchema)19 TableEnvironment (org.apache.flink.table.api.TableEnvironment)17 CatalogPartitionSpec (org.apache.flink.table.catalog.CatalogPartitionSpec)12 Table (org.apache.hadoop.hive.metastore.api.Table)12 Configuration (org.apache.flink.configuration.Configuration)11 SqlCreateHiveTable (org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable)11 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)8 LinkedHashMap (java.util.LinkedHashMap)7 Catalog (org.apache.flink.table.catalog.Catalog)7 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)6 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)6