Search in sources :

Example 11 with TableDescriptor

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

the class PushProjectIntoTableSourceScanRuleTest method testMetadataProjectionWithoutProjectionPushDownWhenSupported.

@Test
public void testMetadataProjectionWithoutProjectionPushDownWhenSupported() {
    final SharedReference<List<String>> appliedKeys = sharedObjects.add(new ArrayList<>());
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(NoPushDownSource.SCHEMA).source(new NoPushDownSource(true, appliedKeys)).build();
    util().tableEnv().createTable("T1", sourceDescriptor);
    util().verifyRelPlan("SELECT m1, metadata FROM T1");
    assertThat(appliedKeys.get(), contains("m1", "m2"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 12 with TableDescriptor

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

the class PushProjectIntoTableSourceScanRuleTest method testProjectionIncludingOnlyMetadata.

@Test
public void testProjectionIncludingOnlyMetadata() {
    final AtomicReference<DataType> appliedProjectionDataType = new AtomicReference<>(null);
    final AtomicReference<DataType> appliedMetadataDataType = new AtomicReference<>(null);
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(PushDownSource.SCHEMA).source(new PushDownSource(appliedProjectionDataType, appliedMetadataDataType)).build();
    util().tableEnv().createTable("T5", sourceDescriptor);
    util().verifyRelPlan("SELECT metadata FROM T5");
    assertThat(appliedProjectionDataType.get(), notNullValue());
    assertThat(appliedMetadataDataType.get(), notNullValue());
    assertThat(DataType.getFieldNames(appliedProjectionDataType.get()), equalTo(Collections.emptyList()));
    assertThat(DataType.getFieldNames(appliedMetadataDataType.get()), equalTo(Collections.singletonList("m2")));
}
Also used : DataType(org.apache.flink.table.types.DataType) AtomicReference(java.util.concurrent.atomic.AtomicReference) TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 13 with TableDescriptor

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

the class PushProjectIntoTableSourceScanRuleTest method testProjectionWithMetadataAndPhysicalFields.

@Test
public void testProjectionWithMetadataAndPhysicalFields() {
    final AtomicReference<DataType> appliedProjectionDataType = new AtomicReference<>(null);
    final AtomicReference<DataType> appliedMetadataDataType = new AtomicReference<>(null);
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(PushDownSource.SCHEMA).source(new PushDownSource(appliedProjectionDataType, appliedMetadataDataType)).build();
    util().tableEnv().createTable("T5", sourceDescriptor);
    util().verifyRelPlan("SELECT metadata, f1 FROM T5");
    assertThat(appliedProjectionDataType.get(), notNullValue());
    assertThat(appliedMetadataDataType.get(), notNullValue());
    assertThat(DataType.getFieldNames(appliedProjectionDataType.get()), equalTo(Collections.singletonList("f1")));
    assertThat(DataType.getFieldNames(appliedMetadataDataType.get()), equalTo(Arrays.asList("f1", "m2")));
}
Also used : DataType(org.apache.flink.table.types.DataType) AtomicReference(java.util.concurrent.atomic.AtomicReference) TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 14 with TableDescriptor

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

the class PushFilterPastChangelogNormalizeRuleTest method testWithMultiplePrimaryKeyColumns.

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

Example 15 with TableDescriptor

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

the class WrapJsonAggFunctionArgumentsRuleTest method testJsonObjectAgg.

@Test
public void testJsonObjectAgg() {
    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_OBJECTAGG(f0 VALUE f0) FROM T");
}
Also used : TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

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