forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-26805][table] Managed table breaks legacy connector without 'c…
…onnector.type' This closes apache#19209
- Loading branch information
1 parent
103fae9
commit 7d7a111
Showing
7 changed files
with
238 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...table-planner/src/test/java/org/apache/flink/connector/file/table/LegacyTableFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.connector.file.table; | ||
|
||
import org.apache.flink.table.api.TableSchema; | ||
import org.apache.flink.table.descriptors.DescriptorProperties; | ||
import org.apache.flink.table.factories.StreamTableSinkFactory; | ||
import org.apache.flink.table.factories.StreamTableSourceFactory; | ||
import org.apache.flink.table.factories.TableFactory; | ||
import org.apache.flink.table.planner.runtime.utils.TestingAppendTableSink; | ||
import org.apache.flink.table.planner.utils.TestTableSource; | ||
import org.apache.flink.table.sinks.StreamTableSink; | ||
import org.apache.flink.table.sources.StreamTableSource; | ||
import org.apache.flink.types.Row; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.flink.table.descriptors.Schema.SCHEMA; | ||
|
||
/** A legacy {@link TableFactory} uses user define options. */ | ||
public class LegacyTableFactory | ||
implements StreamTableSinkFactory<Row>, StreamTableSourceFactory<Row> { | ||
|
||
@Override | ||
public StreamTableSink<Row> createStreamTableSink(Map<String, String> properties) { | ||
DescriptorProperties dp = new DescriptorProperties(); | ||
dp.putProperties(properties); | ||
TableSchema tableSchema = dp.getTableSchema(SCHEMA); | ||
StreamTableSink<Row> sink = new TestingAppendTableSink(); | ||
return (StreamTableSink) | ||
sink.configure(tableSchema.getFieldNames(), tableSchema.getFieldTypes()); | ||
} | ||
|
||
@Override | ||
public StreamTableSource<Row> createStreamTableSource(Map<String, String> properties) { | ||
DescriptorProperties dp = new DescriptorProperties(); | ||
dp.putProperties(properties); | ||
TableSchema tableSchema = dp.getTableSchema(SCHEMA); | ||
return new TestTableSource(false, tableSchema); | ||
} | ||
|
||
@Override | ||
public Map<String, String> requiredContext() { | ||
Map<String, String> options = new HashMap<>(); | ||
options.put("type", "legacy"); | ||
return options; | ||
} | ||
|
||
@Override | ||
public List<String> supportedProperties() { | ||
List<String> properties = new ArrayList<>(); | ||
// schema | ||
properties.add(SCHEMA + ".#." + DescriptorProperties.TYPE); | ||
properties.add(SCHEMA + ".#." + DescriptorProperties.DATA_TYPE); | ||
properties.add(SCHEMA + ".#." + DescriptorProperties.NAME); | ||
properties.add(SCHEMA + ".#." + DescriptorProperties.EXPR); | ||
return properties; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
.../src/test/java/org/apache/flink/table/planner/plan/stream/sql/LegacyTableFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.table.planner.plan.stream.sql; | ||
|
||
import org.apache.flink.connector.file.table.LegacyTableFactory; | ||
import org.apache.flink.table.planner.utils.JavaStreamTableTestUtil; | ||
import org.apache.flink.table.planner.utils.TableTestBase; | ||
|
||
import org.junit.Test; | ||
|
||
/** Tests for usages of {@link LegacyTableFactory}. */ | ||
public class LegacyTableFactoryTest extends TableTestBase { | ||
|
||
private final JavaStreamTableTestUtil util; | ||
|
||
public LegacyTableFactoryTest() { | ||
util = javaStreamTestUtil(); | ||
util.tableEnv().executeSql("CREATE TABLE T (a INT) WITH ('type'='legacy')"); | ||
} | ||
|
||
@Test | ||
public void testSelect() { | ||
util.verifyExecPlan("SELECT * FROM T"); | ||
} | ||
|
||
@Test | ||
public void testInsert() { | ||
util.verifyExecPlanInsert("INSERT INTO T VALUES (1)"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../test/resources/org/apache/flink/table/planner/plan/stream/sql/LegacyTableFactoryTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" ?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to you under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<Root> | ||
<TestCase name="testInsert"> | ||
<Resource name="sql"> | ||
<![CDATA[INSERT INTO T VALUES (1)]]> | ||
</Resource> | ||
<Resource name="ast"> | ||
<![CDATA[ | ||
LogicalLegacySink(name=[`default_catalog`.`default_database`.`T`], fields=[a]) | ||
+- LogicalValues(tuples=[[{ 1 }]]) | ||
]]> | ||
</Resource> | ||
<Resource name="optimized exec plan"> | ||
<![CDATA[ | ||
LegacySink(name=[`default_catalog`.`default_database`.`T`], fields=[a]) | ||
+- Values(tuples=[[{ 1 }]]) | ||
]]> | ||
</Resource> | ||
</TestCase> | ||
<TestCase name="testSelect"> | ||
<Resource name="sql"> | ||
<![CDATA[SELECT * FROM T]]> | ||
</Resource> | ||
<Resource name="ast"> | ||
<![CDATA[ | ||
LogicalProject(a=[$0]) | ||
+- LogicalTableScan(table=[[default_catalog, default_database, T, source: [TestTableSource(a)]]]) | ||
]]> | ||
</Resource> | ||
<Resource name="optimized exec plan"> | ||
<![CDATA[ | ||
LegacyTableSourceScan(table=[[default_catalog, default_database, T, source: [TestTableSource(a)]]], fields=[a]) | ||
]]> | ||
</Resource> | ||
</TestCase> | ||
</Root> |