Search in sources :

Example 6 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class WrapJsonAggFunctionArgumentsRuleTest method testJsonArrayAgg.

@Test
public void testJsonArrayAgg() {
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(Schema.newBuilder().column("f0", STRING()).build()).unboundedScanSource(ChangelogMode.all()).build();
    util.tableEnv().createTable("T", sourceDescriptor);
    util.verifyRelPlan("SELECT JSON_ARRAYAGG(f0) FROM T");
}
Also used : TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 7 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class PushFilterPastChangelogNormalizeRuleTest method testWithSinglePrimaryKeyFilter.

@Test
public void testWithSinglePrimaryKeyFilter() {
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(Schema.newBuilder().column("f0", STRING()).column("f1", INT().notNull()).primaryKey("f1").build()).unboundedScanSource(ChangelogMode.upsert()).build();
    util.tableEnv().createTable("T", sourceDescriptor);
    util.verifyRelPlan("SELECT * FROM T WHERE f1 < 1");
}
Also used : TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 8 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class CommonExecSinkITCase method testUnifiedSinksAreUsableWithDataStreamSinkProvider.

@Test
public void testUnifiedSinksAreUsableWithDataStreamSinkProvider() throws ExecutionException, InterruptedException {
    final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
    final SharedReference<List<RowData>> fetched = sharedObjects.add(new ArrayList<>());
    final List<Row> rows = Arrays.asList(Row.of(1), Row.of(2));
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(Schema.newBuilder().column("a", INT()).build()).source(new TestSource(rows)).sink(buildDataStreamSinkProvider(fetched)).build();
    tableEnv.createTable("T1", sourceDescriptor);
    final String sqlStmt = "INSERT INTO T1 SELECT * FROM T1";
    tableEnv.executeSql(sqlStmt).await();
    final List<Integer> fetchedRows = fetched.get().stream().map(r -> r.getInt(0)).sorted().collect(Collectors.toList());
    assertEquals(fetchedRows.get(0).intValue(), 1);
    assertEquals(fetchedRows.get(1).intValue(), 2);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 9 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class CommonExecSinkITCase method testCharLengthEnforcer.

@Test
public void testCharLengthEnforcer() throws ExecutionException, InterruptedException {
    final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
    final List<Row> rows = Arrays.asList(Row.of(1, "Apache Flink", "SQL RuleZ", 11, 111, "SQL"), Row.of(2, "Apache", "SQL", 22, 222, "Flink"), Row.of(3, "Apache", "Flink", 33, 333, "Apache Flink SQL"), Row.of(4, "Flink Project", "SQL or SeQueL?", 44, 444, "Apache Flink SQL"));
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(schemaForCharLengthEnforcer()).source(new TestSource(rows)).build();
    tableEnv.createTable("T1", sourceDescriptor);
    // Default config - ignore (no trim)
    TableResult result = tableEnv.executeSql("SELECT * FROM T1");
    result.await();
    final List<Row> results = new ArrayList<>();
    result.collect().forEachRemaining(results::add);
    assertThat(results).containsExactlyInAnyOrderElementsOf(rows);
    // accordingly, based on their type length
    try {
        tableEnv.getConfig().set(TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER.key(), ExecutionConfigOptions.TypeLengthEnforcer.TRIM_PAD.name());
        result = tableEnv.executeSql("SELECT * FROM T1");
        result.await();
        final List<Row> expected = Arrays.asList(Row.of(1, "Apache F", "SQL Ru", 11, 111, "SQL"), Row.of(2, "Apache  ", "SQL   ", 22, 222, "Flink"), Row.of(3, "Apache  ", "Flink ", 33, 333, "Apache"), Row.of(4, "Flink Pr", "SQL or", 44, 444, "Apache"));
        final List<Row> resultsTrimmed = new ArrayList<>();
        result.collect().forEachRemaining(resultsTrimmed::add);
        assertThat(resultsTrimmed).containsExactlyInAnyOrderElementsOf(expected);
    } finally {
        tableEnv.getConfig().set(TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER.key(), ExecutionConfigOptions.TypeLengthEnforcer.IGNORE.name());
    }
}
Also used : TableResult(org.apache.flink.table.api.TableResult) ArrayList(java.util.ArrayList) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 10 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class TableImpl method insertInto.

@Override
public TablePipeline insertInto(TableDescriptor descriptor, boolean overwrite) {
    final SchemaTranslator.ConsumingResult schemaTranslationResult = SchemaTranslator.createConsumingResult(tableEnvironment.getCatalogManager().getDataTypeFactory(), getResolvedSchema().toSourceRowDataType(), descriptor.getSchema().orElse(null), false);
    final TableDescriptor updatedDescriptor = descriptor.toBuilder().schema(schemaTranslationResult.getSchema()).build();
    final ResolvedCatalogTable resolvedCatalogBaseTable = tableEnvironment.getCatalogManager().resolveCatalogTable(updatedDescriptor.toCatalogTable());
    return insertInto(ContextResolvedTable.anonymous(resolvedCatalogBaseTable), overwrite);
}
Also used : SchemaTranslator(org.apache.flink.table.catalog.SchemaTranslator) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) TableDescriptor(org.apache.flink.table.api.TableDescriptor)

Aggregations

TableDescriptor (org.apache.flink.table.api.TableDescriptor)22 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)11 List (java.util.List)9 StreamTableEnvironment (org.apache.flink.table.api.bridge.java.StreamTableEnvironment)7 Row (org.apache.flink.types.Row)7 TableResult (org.apache.flink.table.api.TableResult)4 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 SinkFunction (org.apache.flink.streaming.api.functions.sink.SinkFunction)2 SourceFunction (org.apache.flink.streaming.api.functions.source.SourceFunction)2 SinkV1Adapter (org.apache.flink.streaming.api.transformations.SinkV1Adapter)2 Watermark (org.apache.flink.streaming.api.watermark.Watermark)2 TestSink (org.apache.flink.streaming.runtime.operators.sink.TestSink)2