├── .gitignore
├── LICENSE
├── README.md
├── bin
└── sql-gateway.sh
├── conf
├── log4j.properties
├── logback.xml
└── sql-gateway-defaults.yaml
├── e2e-tests
├── README.md
├── cases
│ ├── test-availability.sh
│ ├── test-catalog-and-database.sh
│ ├── test-select-and-insert.sh
│ └── test-table-and-view.sh
├── data
│ ├── nation.tbl
│ └── test-config.yaml
├── run-tests.sh
├── test-commons.sh
├── test-config.sh
└── test-statements.sh
├── pom.xml
├── src
├── main
│ ├── assemblies
│ │ └── bin.xml
│ └── java
│ │ └── com
│ │ └── ververica
│ │ └── flink
│ │ └── table
│ │ └── gateway
│ │ ├── GatewayOptions.java
│ │ ├── GatewayOptionsParser.java
│ │ ├── SqlGateway.java
│ │ ├── config
│ │ ├── ConfigUtil.java
│ │ ├── Environment.java
│ │ └── entries
│ │ │ ├── CatalogEntry.java
│ │ │ ├── ConfigEntry.java
│ │ │ ├── ConfigurationEntry.java
│ │ │ ├── DeploymentEntry.java
│ │ │ ├── ExecutionEntry.java
│ │ │ ├── FunctionEntry.java
│ │ │ ├── ModuleEntry.java
│ │ │ ├── ServerEntry.java
│ │ │ ├── SessionEntry.java
│ │ │ ├── SinkTableEntry.java
│ │ │ ├── SourceSinkTableEntry.java
│ │ │ ├── SourceTableEntry.java
│ │ │ ├── TableEntry.java
│ │ │ ├── TemporalTableEntry.java
│ │ │ └── ViewEntry.java
│ │ ├── context
│ │ ├── DefaultContext.java
│ │ ├── ExecutionContext.java
│ │ └── SessionContext.java
│ │ ├── deployment
│ │ ├── ClusterDescriptorAdapter.java
│ │ ├── ClusterDescriptorAdapterFactory.java
│ │ ├── ProgramDeployer.java
│ │ ├── SessionClusterDescriptorAdapter.java
│ │ └── YarnPerJobClusterDescriptorAdapter.java
│ │ ├── operation
│ │ ├── AbstractJobOperation.java
│ │ ├── CreateViewOperation.java
│ │ ├── DDLOperation.java
│ │ ├── DescribeTableOperation.java
│ │ ├── DropViewOperation.java
│ │ ├── ExplainOperation.java
│ │ ├── InsertOperation.java
│ │ ├── JobOperation.java
│ │ ├── NonJobOperation.java
│ │ ├── Operation.java
│ │ ├── OperationFactory.java
│ │ ├── OperationUtil.java
│ │ ├── ResetOperation.java
│ │ ├── SelectOperation.java
│ │ ├── SetOperation.java
│ │ ├── ShowCatalogsOperation.java
│ │ ├── ShowCurrentCatalogOperation.java
│ │ ├── ShowCurrentDatabaseOperation.java
│ │ ├── ShowDatabasesOperation.java
│ │ ├── ShowFunctionsOperation.java
│ │ ├── ShowModulesOperation.java
│ │ ├── ShowTablesOperation.java
│ │ ├── ShowViewsOperation.java
│ │ ├── SqlCommandParser.java
│ │ ├── SqlParseException.java
│ │ ├── UseCatalogOperation.java
│ │ └── UseDatabaseOperation.java
│ │ ├── rest
│ │ ├── SqlGatewayEndpoint.java
│ │ ├── handler
│ │ │ ├── AbstractHandler.java
│ │ │ ├── AbstractRestHandler.java
│ │ │ ├── GetInfoHandler.java
│ │ │ ├── GetInfoHeaders.java
│ │ │ ├── InFlightRequestTracker.java
│ │ │ ├── JobCancelHandler.java
│ │ │ ├── JobCancelHeaders.java
│ │ │ ├── JobStatusHandler.java
│ │ │ ├── JobStatusHeaders.java
│ │ │ ├── ResultFetchHandler.java
│ │ │ ├── ResultFetchHeaders.java
│ │ │ ├── SessionCloseHandler.java
│ │ │ ├── SessionCloseHeaders.java
│ │ │ ├── SessionCreateHandler.java
│ │ │ ├── SessionCreateHeaders.java
│ │ │ ├── SessionHeartbeatHandler.java
│ │ │ ├── SessionHeartbeatHeaders.java
│ │ │ ├── StatementExecuteHandler.java
│ │ │ └── StatementExecuteHeaders.java
│ │ ├── message
│ │ │ ├── GetInfoResponseBody.java
│ │ │ ├── JobCancelResponseBody.java
│ │ │ ├── JobIdPathParameter.java
│ │ │ ├── JobStatusResponseBody.java
│ │ │ ├── ResultFetchMessageParameters.java
│ │ │ ├── ResultFetchRequestBody.java
│ │ │ ├── ResultFetchResponseBody.java
│ │ │ ├── ResultTokenPathParameter.java
│ │ │ ├── SessionCloseResponseBody.java
│ │ │ ├── SessionCreateRequestBody.java
│ │ │ ├── SessionCreateResponseBody.java
│ │ │ ├── SessionIdPathParameter.java
│ │ │ ├── SessionJobMessageParameters.java
│ │ │ ├── SessionMessageParameters.java
│ │ │ ├── StatementExecuteRequestBody.java
│ │ │ └── StatementExecuteResponseBody.java
│ │ ├── result
│ │ │ ├── ColumnInfo.java
│ │ │ ├── ConstantNames.java
│ │ │ ├── ResultKind.java
│ │ │ ├── ResultSet.java
│ │ │ ├── ResultSetJsonDeserializer.java
│ │ │ └── ResultSetJsonSerializer.java
│ │ └── session
│ │ │ ├── Session.java
│ │ │ ├── SessionID.java
│ │ │ └── SessionManager.java
│ │ ├── result
│ │ ├── AbstractResult.java
│ │ ├── BatchResult.java
│ │ ├── ChangelogResult.java
│ │ ├── Result.java
│ │ ├── ResultDescriptor.java
│ │ ├── ResultUtil.java
│ │ └── TypedResult.java
│ │ ├── sink
│ │ ├── CollectBatchTableSink.java
│ │ └── CollectStreamTableSink.java
│ │ └── utils
│ │ ├── BashJavaUtil.java
│ │ ├── EnvironmentUtil.java
│ │ ├── SqlExecutionException.java
│ │ └── SqlGatewayException.java
└── test
│ ├── assembly
│ ├── test-random-source.xml
│ └── test-table-factories.xml
│ ├── java
│ └── com
│ │ └── ververica
│ │ └── flink
│ │ └── table
│ │ └── gateway
│ │ ├── config
│ │ ├── DependencyTest.java
│ │ ├── EnvironmentTest.java
│ │ └── ExecutionContextTest.java
│ │ ├── operation
│ │ ├── CreateViewOperationTest.java
│ │ ├── DDLOperationTest.java
│ │ ├── DescribeTableOperationTest.java
│ │ ├── DropViewOperationTest.java
│ │ ├── ExplainOperationTest.java
│ │ ├── OperationTestBase.java
│ │ ├── OperationTestUtils.java
│ │ ├── OperationWithUserJarTest.java
│ │ ├── ResetOperationTest.java
│ │ ├── SetOperationTest.java
│ │ ├── ShowCatalogsOperationTest.java
│ │ ├── ShowCurrentCatalogOperationTest.java
│ │ ├── ShowCurrentDatabaseOperationTest.java
│ │ ├── ShowDatabasesOperationTest.java
│ │ ├── ShowFunctionsOperationTest.java
│ │ ├── ShowModulesOperationTest.java
│ │ ├── ShowTablesOperationTest.java
│ │ ├── ShowViewsOperationTest.java
│ │ ├── SqlCommandParserTest.java
│ │ ├── UseCatalogOperationTest.java
│ │ └── UseDatabaseOperationTest.java
│ │ ├── sink
│ │ ├── TestTableSinkFactoryBase.java
│ │ └── dummy
│ │ │ └── DummyTableSinkFactory.java
│ │ ├── source
│ │ ├── TestTableSourceFactoryBase.java
│ │ ├── dummy
│ │ │ └── DummyTableSourceFactory.java
│ │ └── random
│ │ │ ├── RandomSource.java
│ │ │ ├── RandomSourceFactory.java
│ │ │ ├── RandomSourceFunction.java
│ │ │ └── RandomSourceValidator.java
│ │ └── utils
│ │ ├── EnvironmentFileUtil.java
│ │ ├── ResourceFileUtils.java
│ │ ├── SimpleCatalogFactory.java
│ │ └── UserDefinedFunctions.java
│ └── resources
│ ├── META-INF
│ └── services
│ │ └── org.apache.flink.table.factories.TableFactory
│ ├── plan
│ ├── explain-operation-test.test-explain.expected
│ └── operation-with-user-jar-test.test-explain.expected
│ ├── service-file
│ ├── test-factory-services-file
│ └── test-random-source-file
│ ├── test-data.csv
│ ├── test-sql-gateway-catalogs.yaml
│ ├── test-sql-gateway-configuration.yaml
│ ├── test-sql-gateway-defaults.yaml
│ ├── test-sql-gateway-factory.yaml
│ ├── test-sql-gateway-modules.yaml
│ └── test-sql-gateway-streaming.yaml
└── tools
└── maven
├── checkstyle.xml
└── suppressions.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # IntelliJ IDEA Files
26 | .idea
27 | *.iml
28 |
29 | # Maven Files
30 | target
31 | build-target
32 |
--------------------------------------------------------------------------------
/conf/log4j.properties:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | ################################################################################
18 |
19 | # This affects logging for both flink-sql-gateway and Flink
20 | log4j.rootLogger=INFO, file
21 |
22 | # Uncomment this if you want to _only_ change flink-sql-gateway's logging
23 | #log4j.logger.com.ververica.flink.table.gateway=INFO
24 |
25 | # Log all infos in the given file
26 | log4j.appender.file=org.apache.log4j.FileAppender
27 | log4j.appender.file.file=${log.file}
28 | log4j.appender.file.append=false
29 | log4j.appender.file.layout=org.apache.log4j.PatternLayout
30 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
31 |
32 |
--------------------------------------------------------------------------------
/conf/logback.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 | ${log.file}
22 | false
23 |
24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60} %X{sourceThread} - %msg%n
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/e2e-tests/README.md:
--------------------------------------------------------------------------------
1 | # Flink SQL Gateway End-to-End Tests
2 |
3 | This directory contains tests that verify end-to-end behaviour of Flink SQL gateway.
4 |
5 | ## Running Tests
6 |
7 | Before running the tests, you should
8 | 1. have a Flink cluster configured.
9 | 2. have [jq](https://stedolan.github.io/jq/) installed (usually it can be installed easily with package managers like pacman or yum).
10 | 3. `cd` into this `e2e-tests` directory.
11 |
12 | If you want to run the tests on a Flink session cluster, the session cluster must be started before running the tests.
13 |
14 | ### Running Tests against different Execution Targets
15 |
16 | To run the tests against different executors (for example, on a standlone Flink session, a Flink on Yarn session or a Flink on Yarn per-job executor), please change the `execution.target` and other related options in `$FLINK_HOME/conf/flink-conf.yaml` before running the tests. See "Run Gateway with Different Executors" of the documentation in the project root for the detailed settings.
17 |
18 | Note that if you want to run the tests against a Flink on Yarn per job cluster, it's recommended to set both `jobmanager.heap.size` and `taskmanager.memory.process.size` options to `4096m`.
19 |
20 | ### Running Tests on a Local Flink Standalone Session Cluster
21 |
22 | To quickly run the tests on a local Flink standalone session cluster (the job manager and all task managers are on the same local machine), you should first start the local cluster and then run the following command:
23 |
24 | ```
25 | FLINK_HOME= SQL_GATEWAY_HOME= ./run-tests.sh
26 | ```
27 |
28 | where `` is a Flink distribution directory and `` is a Flink SQL gateway distribution directory (containing `bin`, `conf` and `lib` directories). The default value of `` is `/../build-target`.
29 |
30 | ### Running Tests on a Flink Cluster with Multiple Machines
31 |
32 | Running tests on a Flink cluster with multiple machines requires an available HDFS service to store test data such that it can be accessed across multiple machines.
33 |
34 | You can now run all the tests by executing
35 | ```
36 | FLINK_HOME= HDFS_ADDRESS=: SQL_GATEWAY_HOME= ./run-tests.sh
37 | ```
38 |
39 | where `` is a Flink distribution directory, `` is the ip or host name of an hdfs service available and `` is the port of the hdfs service and `` is a Flink SQL gateway distribution directory (containing `bin`, `conf` and `lib` directories). The default value of `` is `/../build-target`.
40 |
--------------------------------------------------------------------------------
/e2e-tests/cases/test-availability.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | ################################################################################
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | ################################################################################
19 |
20 | set -e
21 |
22 | TEST_DIR=$(cd $(dirname $BASH_SOURCE)/..; pwd)
23 | source "$TEST_DIR"/test-statements.sh "$1"
24 | data_dir="$3"
25 |
26 | function cleanup() {
27 | use_database "tmp_db"
28 | drop_table_if_exists "nation"
29 | drop_database_if_exists "tmp_db"
30 | }
31 | trap cleanup EXIT
32 |
33 | use_catalog "default_catalog"
34 | create_database "tmp_db"
35 | use_database "tmp_db"
36 |
37 | nation_table=$(echo `cat < /dev/null
56 | show_modules > /dev/null
57 | describe "nation" > /dev/null
58 | explain "SELECT * FROM nation" > /dev/null
59 |
--------------------------------------------------------------------------------
/e2e-tests/cases/test-select-and-insert.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | ################################################################################
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | ################################################################################
19 |
20 | set -e
21 |
22 | TEST_DIR=$(cd $(dirname $BASH_SOURCE)/..; pwd)
23 | source "$TEST_DIR"/test-statements.sh "$1"
24 | execution_target="$2"
25 | data_dir="$3"
26 |
27 | function cleanup() {
28 | use_database "tmp_db"
29 | drop_table_if_exists "nation"
30 | drop_table_if_exists "res"
31 | drop_database_if_exists "tmp_db"
32 | }
33 | trap cleanup EXIT
34 |
35 | use_catalog "default_catalog"
36 | create_database "tmp_db"
37 | use_database "tmp_db"
38 |
39 | nation_table=$(echo `cat < /dev/null | tail -n 1000`
46 | if [[ $? -ne 0 ]]; then
47 | echo "[ERROR] Cannot run BashJavaUtil to execute command GET_EXECUTION_TARGET." > /dev/stderr
48 | exit 1
49 | fi
50 | echo "$execution_target_output"
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/assemblies/bin.xml:
--------------------------------------------------------------------------------
1 |
19 |
23 | bin
24 |
25 | dir
26 |
27 |
28 | true
29 | flink-sql-gateway-${project.version}
30 |
31 |
32 |
33 | lib
34 | false
35 | false
36 | false
37 | true
38 | true
39 |
40 |
41 |
42 | org.jline:jline-terminal
43 | org.jline:jline-reader
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | ${project.build.directory}/flink-sql-gateway-${project.version}.jar
52 | lib/
53 | 0644
54 |
55 |
56 |
57 |
58 |
59 |
60 | bin
61 | bin
62 | 0755
63 |
64 |
65 |
66 | conf
67 | conf
68 | 0644
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/GatewayOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway;
20 |
21 | import javax.annotation.Nullable;
22 |
23 | import java.net.URL;
24 | import java.util.Collections;
25 | import java.util.List;
26 | import java.util.Optional;
27 |
28 | /**
29 | * Gateway options to configure the gateway server.
30 | */
31 | public class GatewayOptions {
32 | private final boolean isPrintHelp;
33 | private final Integer port;
34 | private final URL defaultConfig;
35 | private final List jars;
36 | private final List libraryDirs;
37 |
38 | public GatewayOptions(
39 | boolean isPrintHelp,
40 | @Nullable Integer port,
41 | @Nullable URL defaultConfig,
42 | @Nullable List jars,
43 | @Nullable List libraryDirs) {
44 | this.isPrintHelp = isPrintHelp;
45 | this.port = port;
46 | this.defaultConfig = defaultConfig;
47 | this.jars = jars != null ? jars : Collections.emptyList();
48 | this.libraryDirs = libraryDirs != null ? libraryDirs : Collections.emptyList();
49 | }
50 |
51 | public boolean isPrintHelp() {
52 | return isPrintHelp;
53 | }
54 |
55 | public Optional getPort() {
56 | return Optional.ofNullable(port);
57 | }
58 |
59 | public Optional getDefaultConfig() {
60 | return Optional.ofNullable(defaultConfig);
61 | }
62 |
63 | public List getJars() {
64 | return jars;
65 | }
66 |
67 | public List getLibraryDirs() {
68 | return libraryDirs;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/CatalogEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import com.ververica.flink.table.gateway.config.ConfigUtil;
22 |
23 | import org.apache.flink.table.descriptors.DescriptorProperties;
24 |
25 | import java.util.Collections;
26 | import java.util.Map;
27 |
28 | import static org.apache.flink.table.descriptors.CatalogDescriptorValidator.CATALOG_PROPERTY_VERSION;
29 | import static org.apache.flink.table.descriptors.CatalogDescriptorValidator.CATALOG_TYPE;
30 |
31 | /**
32 | * Describes a catalog configuration entry.
33 | */
34 | public class CatalogEntry extends ConfigEntry {
35 |
36 | public static final String CATALOG_NAME = "name";
37 |
38 | private final String name;
39 |
40 | protected CatalogEntry(String name, DescriptorProperties properties) {
41 | super(properties);
42 | this.name = name;
43 | }
44 |
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | @Override
50 | protected void validate(DescriptorProperties properties) {
51 | properties.validateString(CATALOG_TYPE, false, 1);
52 | properties.validateInt(CATALOG_PROPERTY_VERSION, true, 0);
53 |
54 | // further validation is performed by the discovered factory
55 | }
56 |
57 | public static CatalogEntry create(Map config) {
58 | return create(ConfigUtil.normalizeYaml(config));
59 | }
60 |
61 | private static CatalogEntry create(DescriptorProperties properties) {
62 | properties.validateString(CATALOG_NAME, false, 1);
63 |
64 | final String name = properties.getString(CATALOG_NAME);
65 |
66 | final DescriptorProperties cleanedProperties =
67 | properties.withoutKeys(Collections.singletonList(CATALOG_NAME));
68 |
69 | return new CatalogEntry(name, cleanedProperties);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/ConfigEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import com.ververica.flink.table.gateway.utils.SqlGatewayException;
22 |
23 | import org.apache.flink.table.api.ValidationException;
24 | import org.apache.flink.table.descriptors.DescriptorProperties;
25 |
26 | import java.util.Map;
27 | import java.util.Objects;
28 |
29 | /**
30 | * Describes an environment configuration entry (such as catalogs, table, functions, views). Config entries
31 | * are similar to {@link org.apache.flink.table.descriptors.Descriptor} but apply to SQL Gateway's
32 | * environment files only.
33 | */
34 | abstract class ConfigEntry {
35 |
36 | protected final DescriptorProperties properties;
37 |
38 | protected ConfigEntry(DescriptorProperties properties) {
39 | try {
40 | validate(properties);
41 | } catch (ValidationException e) {
42 | throw new SqlGatewayException("Invalid configuration entry.", e);
43 | }
44 |
45 | this.properties = properties;
46 | }
47 |
48 | /**
49 | * Performs syntactic validation.
50 | */
51 | protected abstract void validate(DescriptorProperties properties);
52 |
53 | public Map asMap() {
54 | return properties.asMap();
55 | }
56 |
57 | @Override
58 | public boolean equals(Object o) {
59 | if (this == o) {
60 | return true;
61 | }
62 | if (o == null || getClass() != o.getClass()) {
63 | return false;
64 | }
65 | ConfigEntry that = (ConfigEntry) o;
66 | return Objects.equals(properties, that.properties);
67 | }
68 |
69 | @Override
70 | public int hashCode() {
71 | return Objects.hash(properties);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/FunctionEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import com.ververica.flink.table.gateway.config.ConfigUtil;
22 |
23 | import org.apache.flink.table.descriptors.DescriptorProperties;
24 | import org.apache.flink.table.descriptors.FunctionDescriptor;
25 | import org.apache.flink.table.descriptors.FunctionDescriptorValidator;
26 |
27 | import java.util.Collections;
28 | import java.util.Map;
29 |
30 | /**
31 | * Describes a user-defined function configuration entry.
32 | */
33 | public class FunctionEntry extends ConfigEntry {
34 |
35 | public static final String FUNCTIONS_NAME = "name";
36 |
37 | private String name;
38 |
39 | private FunctionEntry(String name, DescriptorProperties properties) {
40 | super(properties);
41 | this.name = name;
42 | }
43 |
44 | @Override
45 | protected void validate(DescriptorProperties properties) {
46 | new FunctionDescriptorValidator().validate(properties);
47 | }
48 |
49 | public String getName() {
50 | return name;
51 | }
52 |
53 | public FunctionDescriptor getDescriptor() {
54 | return new FunctionEntryDescriptor();
55 | }
56 |
57 | public static FunctionEntry create(Map config) {
58 | return create(ConfigUtil.normalizeYaml(config));
59 | }
60 |
61 | private static FunctionEntry create(DescriptorProperties properties) {
62 | properties.validateString(FUNCTIONS_NAME, false, 1);
63 |
64 | final String name = properties.getString(FUNCTIONS_NAME);
65 |
66 | final DescriptorProperties cleanedProperties =
67 | properties.withoutKeys(Collections.singletonList(FUNCTIONS_NAME));
68 |
69 | return new FunctionEntry(name, cleanedProperties);
70 | }
71 |
72 | // --------------------------------------------------------------------------------------------
73 |
74 | private class FunctionEntryDescriptor extends FunctionDescriptor {
75 |
76 | @Override
77 | public Map toProperties() {
78 | return FunctionEntry.this.properties.asMap();
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/ModuleEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import com.ververica.flink.table.gateway.config.ConfigUtil;
22 |
23 | import org.apache.flink.table.descriptors.DescriptorProperties;
24 |
25 | import java.util.Collections;
26 | import java.util.Map;
27 |
28 | import static org.apache.flink.table.descriptors.ModuleDescriptorValidator.MODULE_TYPE;
29 |
30 | /**
31 | * Describes a module configuration entry.
32 | */
33 | public class ModuleEntry extends ConfigEntry {
34 |
35 | public static final String MODULE_NAME = "name";
36 |
37 | private final String name;
38 |
39 | protected ModuleEntry(String name, DescriptorProperties properties) {
40 | super(properties);
41 | this.name = name;
42 | }
43 |
44 | public String getName() {
45 | return name;
46 | }
47 |
48 | @Override
49 | protected void validate(DescriptorProperties properties) {
50 | properties.validateString(MODULE_TYPE, false, 1);
51 |
52 | // further validation is performed by the discovered factory
53 | }
54 |
55 | public static ModuleEntry create(Map config) {
56 | return create(ConfigUtil.normalizeYaml(config));
57 | }
58 |
59 | private static ModuleEntry create(DescriptorProperties properties) {
60 | properties.validateString(MODULE_NAME, false, 1);
61 |
62 | final String name = properties.getString(MODULE_NAME);
63 |
64 | final DescriptorProperties cleanedProperties =
65 | properties.withoutKeys(Collections.singletonList(MODULE_NAME));
66 |
67 | return new ModuleEntry(name, cleanedProperties);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/SinkTableEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import org.apache.flink.table.descriptors.DescriptorProperties;
22 |
23 | /**
24 | * Configuration of a table sink.
25 | */
26 | public class SinkTableEntry extends TableEntry {
27 |
28 | SinkTableEntry(String name, DescriptorProperties properties) {
29 | super(name, properties);
30 | }
31 |
32 | @Override
33 | protected void validate(DescriptorProperties properties) {
34 | // validation is performed by the discovered factory
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/SourceSinkTableEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import org.apache.flink.table.descriptors.DescriptorProperties;
22 |
23 | /**
24 | * Configuration of a table source and sink.
25 | */
26 | public class SourceSinkTableEntry extends TableEntry {
27 |
28 | SourceSinkTableEntry(String name, DescriptorProperties properties) {
29 | super(name, properties);
30 | }
31 |
32 | @Override
33 | protected void validate(DescriptorProperties properties) {
34 | // validation is performed by the discovered factory
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/SourceTableEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import org.apache.flink.table.descriptors.DescriptorProperties;
22 |
23 | /**
24 | * Configuration of a table source.
25 | */
26 | public class SourceTableEntry extends TableEntry {
27 |
28 | SourceTableEntry(String name, DescriptorProperties properties) {
29 | super(name, properties);
30 | }
31 |
32 | @Override
33 | protected void validate(DescriptorProperties properties) {
34 | // validation is performed by the discovered factory
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/TemporalTableEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import org.apache.flink.table.descriptors.DescriptorProperties;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * Configuration of a temporal table.
27 | * TODO remove this.
28 | */
29 | public class TemporalTableEntry extends TableEntry {
30 |
31 | private static final String TABLES_HISTORY_TABLE = "history-table";
32 |
33 | private static final String TABLES_PRIMARY_KEY = "primary-key";
34 |
35 | private static final String TABLES_TIME_ATTRIBUTE = "time-attribute";
36 |
37 | private final String historyTable;
38 |
39 | private final List primaryKeyFields;
40 |
41 | private final String timeAttribute;
42 |
43 | TemporalTableEntry(String name, DescriptorProperties properties) {
44 | super(name, properties);
45 |
46 | historyTable = properties.getString(TABLES_HISTORY_TABLE);
47 | primaryKeyFields = properties.getArray(TABLES_PRIMARY_KEY, properties::getString);
48 | timeAttribute = properties.getString(TABLES_TIME_ATTRIBUTE);
49 | }
50 |
51 | public String getHistoryTable() {
52 | return historyTable;
53 | }
54 |
55 | public List getPrimaryKeyFields() {
56 | return primaryKeyFields;
57 | }
58 |
59 | public String getTimeAttribute() {
60 | return timeAttribute;
61 | }
62 |
63 | @Override
64 | protected void validate(DescriptorProperties properties) {
65 | properties.validateString(TABLES_HISTORY_TABLE, false, 1);
66 | properties.validateArray(
67 | TABLES_PRIMARY_KEY,
68 | (key) -> properties.validateString(key, false, 1),
69 | 1,
70 | 1); // currently, composite primary keys are not supported
71 | properties.validateString(TABLES_TIME_ATTRIBUTE, false, 1);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/config/entries/ViewEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.config.entries;
20 |
21 | import org.apache.flink.table.descriptors.DescriptorProperties;
22 |
23 | /**
24 | * Configuration of a table view.
25 | */
26 | public class ViewEntry extends TableEntry {
27 |
28 | private static final String TABLES_QUERY = "query";
29 |
30 | private final String query;
31 |
32 | ViewEntry(String name, DescriptorProperties properties) {
33 | super(name, properties);
34 |
35 | query = properties.getString(TABLES_QUERY);
36 | }
37 |
38 | public String getQuery() {
39 | return query;
40 | }
41 |
42 | @Override
43 | protected void validate(DescriptorProperties properties) {
44 | properties.validateString(TABLES_QUERY, false, 1);
45 | }
46 |
47 | public static ViewEntry create(String name, String query) {
48 | final DescriptorProperties properties = new DescriptorProperties(true);
49 | properties.putString(TABLES_QUERY, query);
50 | return new ViewEntry(name, properties);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/deployment/ClusterDescriptorAdapterFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.deployment;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 |
23 | import org.apache.flink.api.common.JobID;
24 | import org.apache.flink.configuration.Configuration;
25 | import org.apache.flink.configuration.DeploymentOptions;
26 | import org.apache.flink.yarn.executors.YarnJobClusterExecutor;
27 |
28 | /**
29 | * The factory to create {@link ClusterDescriptorAdapter} based on execution.target.
30 | */
31 | public class ClusterDescriptorAdapterFactory {
32 |
33 | public static ClusterDescriptorAdapter create(
34 | ExecutionContext executionContext,
35 | Configuration configuration,
36 | String sessionId,
37 | JobID jobId) {
38 | String executionTarget = executionContext.getFlinkConfig().getString(DeploymentOptions.TARGET);
39 | if (executionTarget == null) {
40 | throw new RuntimeException("No execution.target specified in your configuration file.");
41 | }
42 |
43 | ClusterDescriptorAdapter clusterDescriptorAdapter;
44 |
45 | if (YarnJobClusterExecutor.NAME.equals(executionTarget)) {
46 | clusterDescriptorAdapter = new YarnPerJobClusterDescriptorAdapter<>(
47 | executionContext,
48 | configuration,
49 | sessionId,
50 | jobId);
51 | } else {
52 | clusterDescriptorAdapter = new SessionClusterDescriptorAdapter<>(
53 | executionContext,
54 | configuration,
55 | sessionId,
56 | jobId);
57 | }
58 |
59 | return clusterDescriptorAdapter;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/deployment/SessionClusterDescriptorAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.deployment;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 |
23 | import org.apache.flink.api.common.JobID;
24 | import org.apache.flink.api.common.JobStatus;
25 | import org.apache.flink.configuration.Configuration;
26 |
27 | /**
28 | * Handle job actions based on session mode.
29 | */
30 | public class SessionClusterDescriptorAdapter extends ClusterDescriptorAdapter {
31 | public SessionClusterDescriptorAdapter(
32 | ExecutionContext executionContext,
33 | Configuration configuration,
34 | String sessionId,
35 | JobID jobId) {
36 | super(executionContext, configuration, sessionId, jobId);
37 | }
38 |
39 | @Override
40 | public boolean isGloballyTerminalState() {
41 | JobStatus jobStatus = getJobStatus();
42 | return jobStatus.isGloballyTerminalState();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/deployment/YarnPerJobClusterDescriptorAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.deployment;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 |
23 | import org.apache.flink.api.common.JobID;
24 | import org.apache.flink.api.common.JobStatus;
25 | import org.apache.flink.configuration.Configuration;
26 |
27 | import org.apache.commons.lang3.StringUtils;
28 | import org.slf4j.Logger;
29 | import org.slf4j.LoggerFactory;
30 |
31 | /**
32 | * Handle job actions based on yarn-per-job mode.
33 | */
34 | public class YarnPerJobClusterDescriptorAdapter extends ClusterDescriptorAdapter {
35 | private static final Logger LOG = LoggerFactory.getLogger(YarnPerJobClusterDescriptorAdapter.class);
36 |
37 | public YarnPerJobClusterDescriptorAdapter(
38 | ExecutionContext executionContext,
39 | Configuration configuration,
40 | String sessionId,
41 | JobID jobId) {
42 | super(executionContext, configuration, sessionId, jobId);
43 | }
44 |
45 | @Override
46 | public boolean isGloballyTerminalState() {
47 | boolean isGloballyTerminalState;
48 | try {
49 | JobStatus jobStatus = getJobStatus();
50 | isGloballyTerminalState = jobStatus.isGloballyTerminalState();
51 | } catch (Exception e) {
52 | if (isYarnApplicationStopped(e)) {
53 | isGloballyTerminalState = true;
54 | } else {
55 | throw e;
56 | }
57 | }
58 |
59 | return isGloballyTerminalState;
60 | }
61 |
62 | /**
63 | * The yarn application is not running when its final status is not UNDEFINED.
64 | *
65 | *
In this case, it will throw
66 | * RuntimeException("The Yarn application " + applicationId + " doesn't run anymore.")
67 | * from retrieve method in YarnClusterDescriptor.java
68 | */
69 | private boolean isYarnApplicationStopped(Throwable e) {
70 | do {
71 | String exceptionMessage = e.getMessage();
72 | if (StringUtils.equals(exceptionMessage, "The Yarn application " + clusterID + " doesn't run anymore.")) {
73 | LOG.info("{} is stopped.", clusterID);
74 | return true;
75 | }
76 | e = e.getCause();
77 | } while (e != null);
78 | return false;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/CreateViewOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.config.entries.TableEntry;
23 | import com.ververica.flink.table.gateway.config.entries.ViewEntry;
24 | import com.ververica.flink.table.gateway.context.ExecutionContext;
25 | import com.ververica.flink.table.gateway.context.SessionContext;
26 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
27 | import com.ververica.flink.table.gateway.utils.SqlExecutionException;
28 |
29 | import org.apache.flink.table.api.TableEnvironment;
30 |
31 | /**
32 | * Operation for CREATE VIEW command.
33 | */
34 | public class CreateViewOperation implements NonJobOperation {
35 | private final ExecutionContext> context;
36 | private final String viewName;
37 | private final String query;
38 |
39 | public CreateViewOperation(SessionContext context, String viewName, String query) {
40 | this.context = context.getExecutionContext();
41 | this.viewName = viewName;
42 | this.query = query;
43 | }
44 |
45 | @Override
46 | public ResultSet execute() {
47 | Environment env = context.getEnvironment();
48 | TableEntry tableEntry = env.getTables().get(viewName);
49 | if (tableEntry instanceof ViewEntry) {
50 | throw new SqlExecutionException("'" + viewName + "' has already been defined in the current session.");
51 | }
52 |
53 | // TODO check the logic
54 | TableEnvironment tableEnv = context.getTableEnvironment();
55 | try {
56 | context.wrapClassLoader(() -> {
57 | tableEnv.createTemporaryView(viewName, tableEnv.sqlQuery(query));
58 | return null;
59 | });
60 | } catch (Throwable t) {
61 | // catch everything such that the query does not crash the executor
62 | throw new SqlExecutionException("Invalid SQL statement.", t);
63 | }
64 | // Also attach the view to ExecutionContext#environment.
65 | env.getTables().put(viewName, ViewEntry.create(viewName, query));
66 | return OperationUtil.OK;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/JobOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
22 |
23 | import org.apache.flink.api.common.JobID;
24 | import org.apache.flink.api.common.JobStatus;
25 |
26 | import java.util.Optional;
27 |
28 | /**
29 | * An operation will submit a flink job, the corresponding command can be SELECT or INSERT.
30 | */
31 | public interface JobOperation extends Operation {
32 |
33 | /**
34 | * Returns the job id after submit the job, that means execute method has been called.
35 | */
36 | JobID getJobId();
37 |
38 | /**
39 | * Get a part of job execution result, this method may be called many times to get all result.
40 | * Returns Optional.empty if no more results need to be returned,
41 | * else returns ResultSet (even if the data in the ResultSet is empty).
42 | *
43 | *
The token must be equal to the previous token + 1 or must be same with the previous token.
44 | * otherwise a SqlGatewayException will be thrown. This method should return the same result for the same token.
45 | *
46 | *
The size of result data must be less than maxFetchSize if it's is positive value, else ignore it.
47 | * Note: the maxFetchSize must be same for same token in each call, else a SqlGatewayException will be thrown.
48 | */
49 | Optional getJobResult(long token, int maxFetchSize);
50 |
51 | /**
52 | * Returns the status of the flink job.
53 | */
54 | JobStatus getJobStatus();
55 |
56 | /**
57 | * Cancel the flink job.
58 | */
59 | void cancelJob();
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/NonJobOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | /**
22 | * An operation just execute in local (will not submit a flink job), the corresponding command can be SHOW, CREATE...
23 | */
24 | public interface NonJobOperation extends Operation {
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/Operation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
22 |
23 | /**
24 | * Operation is a specific representation of a command (e.g. SELECT, SHOW, CREATE),
25 | * which could execute the command and return the result.
26 | */
27 | public interface Operation {
28 |
29 | /**
30 | * Execute the command and return the result.
31 | */
32 | ResultSet execute();
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/OperationUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
22 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
23 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.types.logical.VarCharType;
27 | import org.apache.flink.types.Row;
28 |
29 | import java.util.ArrayList;
30 | import java.util.List;
31 |
32 | /**
33 | * Utility class for {@link Operation}.
34 | */
35 | public class OperationUtil {
36 |
37 | public static final ResultSet OK = ResultSet.builder()
38 | .resultKind(ResultKind.SUCCESS)
39 | .columns(ColumnInfo.create(ConstantNames.RESULT, new VarCharType(2)))
40 | .data(Row.of(ConstantNames.OK))
41 | .build();
42 |
43 | public static ResultSet singleStringToResultSet(String str, String columnName) {
44 | boolean isNullable;
45 | int length;
46 |
47 | if (str == null) {
48 | isNullable = true;
49 | length = VarCharType.DEFAULT_LENGTH;
50 | } else {
51 | isNullable = false;
52 | length = str.length();
53 | }
54 |
55 | return ResultSet.builder()
56 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
57 | .columns(ColumnInfo.create(columnName, new VarCharType(isNullable, length)))
58 | .data(Row.of(str))
59 | .build();
60 | }
61 |
62 | public static ResultSet stringListToResultSet(List strings, String columnName) {
63 | List data = new ArrayList<>();
64 | boolean isNullable = false;
65 | int maxLength = VarCharType.DEFAULT_LENGTH;
66 |
67 | for (String str : strings) {
68 | if (str == null) {
69 | isNullable = true;
70 | } else {
71 | maxLength = Math.max(str.length(), maxLength);
72 | data.add(Row.of(str));
73 | }
74 | }
75 |
76 | return ResultSet.builder()
77 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
78 | .columns(ColumnInfo.create(columnName, new VarCharType(isNullable, maxLength)))
79 | .data(data)
80 | .build();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ResetOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
24 |
25 | /**
26 | * Operation for RESET command.
27 | */
28 | public class ResetOperation implements NonJobOperation {
29 | private final SessionContext context;
30 |
31 | public ResetOperation(SessionContext context) {
32 | this.context = context;
33 | }
34 |
35 | @Override
36 | public ResultSet execute() {
37 | ExecutionContext> executionContext = context.getExecutionContext();
38 | // Renew the ExecutionContext by merging the default environment with original session context.
39 | // Book keep all the session states of current ExecutionContext then
40 | // re-register them into the new one.
41 | ExecutionContext> newExecutionContext = context
42 | .createExecutionContextBuilder(context.getOriginalSessionEnv())
43 | .sessionState(executionContext.getSessionState())
44 | .build();
45 | context.setExecutionContext(newExecutionContext);
46 |
47 | return OperationUtil.OK;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowCatalogsOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 |
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | /**
32 | * Operation for SHOW CATALOGS command.
33 | */
34 | public class ShowCatalogsOperation implements NonJobOperation {
35 | private final ExecutionContext> context;
36 |
37 | public ShowCatalogsOperation(SessionContext context) {
38 | this.context = context.getExecutionContext();
39 | }
40 |
41 | @Override
42 | public ResultSet execute() {
43 | final TableEnvironment tableEnv = context.getTableEnvironment();
44 | final List catalogs = context.wrapClassLoader(() -> Arrays.asList(tableEnv.listCatalogs()));
45 | return OperationUtil.stringListToResultSet(catalogs, ConstantNames.SHOW_CATALOGS_RESULT);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowCurrentCatalogOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 |
28 | /**
29 | * Operation for SHOW CURRENT CATALOG command.
30 | */
31 | public class ShowCurrentCatalogOperation implements NonJobOperation {
32 | private final ExecutionContext> context;
33 |
34 | public ShowCurrentCatalogOperation(SessionContext context) {
35 | this.context = context.getExecutionContext();
36 | }
37 |
38 | @Override
39 | public ResultSet execute() {
40 | final TableEnvironment tableEnv = context.getTableEnvironment();
41 | return OperationUtil.singleStringToResultSet(
42 | context.wrapClassLoader(tableEnv::getCurrentCatalog), ConstantNames.SHOW_CURRENT_CATALOG_RESULT);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowCurrentDatabaseOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 |
28 | /**
29 | * Operation for SHOW CURRENT DATABASE command.
30 | */
31 | public class ShowCurrentDatabaseOperation implements NonJobOperation {
32 | private final ExecutionContext> context;
33 |
34 | public ShowCurrentDatabaseOperation(SessionContext context) {
35 | this.context = context.getExecutionContext();
36 | }
37 |
38 | @Override
39 | public ResultSet execute() {
40 | final TableEnvironment tableEnv = context.getTableEnvironment();
41 | return OperationUtil.singleStringToResultSet(
42 | context.wrapClassLoader(tableEnv::getCurrentDatabase), ConstantNames.SHOW_CURRENT_DATABASE_RESULT);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowDatabasesOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 |
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | /**
32 | * Operation for SHOW DATABASES command.
33 | */
34 | public class ShowDatabasesOperation implements NonJobOperation {
35 | private final ExecutionContext> context;
36 |
37 | public ShowDatabasesOperation(SessionContext context) {
38 | this.context = context.getExecutionContext();
39 | }
40 |
41 | @Override
42 | public ResultSet execute() {
43 | final TableEnvironment tableEnv = context.getTableEnvironment();
44 | final List databases = context.wrapClassLoader(() -> Arrays.asList(tableEnv.listDatabases()));
45 | return OperationUtil.stringListToResultSet(databases, ConstantNames.SHOW_DATABASES_RESULT);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowFunctionsOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 |
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | /**
32 | * Operation for SHOW FUNCTIONS command.
33 | */
34 | public class ShowFunctionsOperation implements NonJobOperation {
35 | private final ExecutionContext> context;
36 |
37 | public ShowFunctionsOperation(SessionContext context) {
38 | this.context = context.getExecutionContext();
39 | }
40 |
41 | @Override
42 | public ResultSet execute() {
43 | final TableEnvironment tableEnv = context.getTableEnvironment();
44 | final List functions = context.wrapClassLoader(() -> Arrays.asList(tableEnv.listFunctions()));
45 | return OperationUtil.stringListToResultSet(functions, ConstantNames.SHOW_FUNCTIONS_RESULT);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowModulesOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 |
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | /**
32 | * Operation for SHOW MODULES command.
33 | */
34 | public class ShowModulesOperation implements NonJobOperation {
35 | private final ExecutionContext> context;
36 |
37 | public ShowModulesOperation(SessionContext context) {
38 | this.context = context.getExecutionContext();
39 | }
40 |
41 | @Override
42 | public ResultSet execute() {
43 | final TableEnvironment tableEnv = context.getTableEnvironment();
44 | final List modules = context.wrapClassLoader(() -> Arrays.asList(tableEnv.listModules()));
45 | return OperationUtil.stringListToResultSet(modules, ConstantNames.SHOW_MODULES_RESULT);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowTablesOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
24 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
25 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
26 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
27 |
28 | import org.apache.flink.table.api.TableEnvironment;
29 | import org.apache.flink.table.types.logical.VarCharType;
30 | import org.apache.flink.types.Row;
31 |
32 | import java.util.ArrayList;
33 | import java.util.Arrays;
34 | import java.util.List;
35 |
36 | /**
37 | * Operation for SHOW TABLES command.
38 | */
39 | public class ShowTablesOperation implements NonJobOperation {
40 | private final ExecutionContext> context;
41 |
42 | public ShowTablesOperation(SessionContext context) {
43 | this.context = context.getExecutionContext();
44 | }
45 |
46 | @Override
47 | public ResultSet execute() {
48 | List rows = new ArrayList<>();
49 | int maxNameLength = 1;
50 |
51 | final TableEnvironment tableEnv = context.getTableEnvironment();
52 | // listTables will return all tables and views
53 | for (String table : context.wrapClassLoader(() -> Arrays.asList(tableEnv.listTables()))) {
54 | rows.add(Row.of(table));
55 | maxNameLength = Math.max(maxNameLength, table.length());
56 | }
57 |
58 | return ResultSet.builder()
59 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
60 | .columns(ColumnInfo.create(ConstantNames.SHOW_TABLES_RESULT, new VarCharType(false, maxNameLength)))
61 | .data(rows)
62 | .build();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/ShowViewsOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.entries.TableEntry;
22 | import com.ververica.flink.table.gateway.config.entries.ViewEntry;
23 | import com.ververica.flink.table.gateway.context.ExecutionContext;
24 | import com.ververica.flink.table.gateway.context.SessionContext;
25 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
26 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
27 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
28 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
29 |
30 | import org.apache.flink.table.types.logical.VarCharType;
31 | import org.apache.flink.types.Row;
32 |
33 | import java.util.ArrayList;
34 | import java.util.List;
35 | import java.util.Map;
36 |
37 | /**
38 | * Operation for SHOW VIEWS command.
39 | */
40 | public class ShowViewsOperation implements NonJobOperation {
41 |
42 | private final ExecutionContext> context;
43 |
44 | public ShowViewsOperation(SessionContext context) {
45 | this.context = context.getExecutionContext();
46 | }
47 |
48 | @Override
49 | public ResultSet execute() {
50 | List rows = new ArrayList<>();
51 | int maxNameLength = 1;
52 |
53 | for (Map.Entry entry : context.getEnvironment().getTables().entrySet()) {
54 | if (entry.getValue() instanceof ViewEntry) {
55 | String name = entry.getKey();
56 | rows.add(Row.of(name));
57 | maxNameLength = Math.max(maxNameLength, name.length());
58 | }
59 | }
60 |
61 | return ResultSet.builder()
62 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
63 | .columns(ColumnInfo.create(ConstantNames.SHOW_VIEWS_RESULT, new VarCharType(false, maxNameLength)))
64 | .data(rows)
65 | .build();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/SqlParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | /**
22 | * Exception thrown during parsing SQL statement.
23 | */
24 | public class SqlParseException extends RuntimeException {
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | public SqlParseException(String message) {
29 | super(message);
30 | }
31 |
32 | public SqlParseException(String message, Throwable e) {
33 | super(message, e);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/UseCatalogOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
24 | import com.ververica.flink.table.gateway.utils.SqlExecutionException;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 | import org.apache.flink.table.catalog.exceptions.CatalogException;
28 |
29 | /**
30 | * Operation for USE CATALOG command.
31 | */
32 | public class UseCatalogOperation implements NonJobOperation {
33 | private final ExecutionContext> context;
34 | private final String catalogName;
35 |
36 | public UseCatalogOperation(SessionContext context, String catalogName) {
37 | this.context = context.getExecutionContext();
38 | this.catalogName = catalogName;
39 | }
40 |
41 | @Override
42 | public ResultSet execute() {
43 | final TableEnvironment tableEnv = context.getTableEnvironment();
44 |
45 | context.wrapClassLoader(() -> {
46 | // Rely on TableEnvironment/CatalogManager to validate input
47 | try {
48 | tableEnv.useCatalog(catalogName);
49 | return null;
50 | } catch (CatalogException e) {
51 | throw new SqlExecutionException("Failed to switch to catalog " + catalogName, e);
52 | }
53 | });
54 |
55 | return OperationUtil.OK;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/operation/UseDatabaseOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.context.ExecutionContext;
22 | import com.ververica.flink.table.gateway.context.SessionContext;
23 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
24 | import com.ververica.flink.table.gateway.utils.SqlExecutionException;
25 |
26 | import org.apache.flink.table.api.TableEnvironment;
27 | import org.apache.flink.table.catalog.exceptions.CatalogException;
28 |
29 | /**
30 | * Operation for USE DATABASE command.
31 | */
32 | public class UseDatabaseOperation implements NonJobOperation {
33 | private final ExecutionContext> context;
34 | private final String databaseName;
35 |
36 | public UseDatabaseOperation(SessionContext context, String databaseName) {
37 | this.context = context.getExecutionContext();
38 | this.databaseName = databaseName;
39 | }
40 |
41 | @Override
42 | public ResultSet execute() {
43 | final TableEnvironment tableEnv = context.getTableEnvironment();
44 |
45 | context.wrapClassLoader(() -> {
46 | // Rely on TableEnvironment/CatalogManager to validate input
47 | try {
48 | tableEnv.useDatabase(databaseName);
49 | return null;
50 | } catch (CatalogException e) {
51 | throw new SqlExecutionException("Failed to switch to database " + databaseName, e);
52 | }
53 | });
54 |
55 | return OperationUtil.OK;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/GetInfoHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.GetInfoResponseBody;
22 |
23 | import org.apache.flink.api.common.time.Time;
24 | import org.apache.flink.runtime.rest.handler.HandlerRequest;
25 | import org.apache.flink.runtime.rest.handler.RestHandlerException;
26 | import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
27 | import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
28 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
29 | import org.apache.flink.runtime.util.EnvironmentInformation;
30 |
31 | import javax.annotation.Nonnull;
32 |
33 | import java.util.Map;
34 | import java.util.concurrent.CompletableFuture;
35 |
36 | /**
37 | * Request handler for getting info.
38 | */
39 | public class GetInfoHandler
40 | extends AbstractRestHandler {
41 |
42 | public GetInfoHandler(
43 | Time timeout,
44 | Map responseHeaders,
45 | MessageHeaders messageHeaders) {
46 |
47 | super(timeout, responseHeaders, messageHeaders);
48 | }
49 |
50 | @Override
51 | protected CompletableFuture handleRequest(
52 | @Nonnull HandlerRequest request) throws RestHandlerException {
53 | String version = EnvironmentInformation.getVersion();
54 | return CompletableFuture.completedFuture(new GetInfoResponseBody("Apache Flink", version));
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/GetInfoHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.GetInfoResponseBody;
22 |
23 | import org.apache.flink.runtime.rest.HttpMethodWrapper;
24 | import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
25 | import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
26 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
27 |
28 | import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
29 |
30 | /**
31 | * Message headers for getting info.
32 | */
33 | public class GetInfoHeaders
34 | implements MessageHeaders {
35 |
36 | private static final GetInfoHeaders INSTANCE = new GetInfoHeaders();
37 |
38 | public static final String URL = "/info";
39 |
40 | private GetInfoHeaders() {
41 | }
42 |
43 | @Override
44 | public Class getResponseClass() {
45 | return GetInfoResponseBody.class;
46 | }
47 |
48 | @Override
49 | public HttpResponseStatus getResponseStatusCode() {
50 | return HttpResponseStatus.OK;
51 | }
52 |
53 | @Override
54 | public String getDescription() {
55 | return "Get meta data for this cluster";
56 | }
57 |
58 | @Override
59 | public Class getRequestClass() {
60 | return EmptyRequestBody.class;
61 | }
62 |
63 | @Override
64 | public EmptyMessageParameters getUnresolvedMessageParameters() {
65 | return EmptyMessageParameters.getInstance();
66 | }
67 |
68 | @Override
69 | public HttpMethodWrapper getHttpMethod() {
70 | return HttpMethodWrapper.GET;
71 | }
72 |
73 | @Override
74 | public String getTargetRestEndpointURL() {
75 | return URL;
76 | }
77 |
78 | public static GetInfoHeaders getInstance() {
79 | return INSTANCE;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/InFlightRequestTracker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import org.apache.flink.runtime.rest.handler.AbstractHandler;
22 |
23 | import javax.annotation.concurrent.ThreadSafe;
24 |
25 | import java.util.concurrent.CompletableFuture;
26 | import java.util.concurrent.Phaser;
27 |
28 | /**
29 | * Tracks in-flight client requests.
30 | *
31 | * @see AbstractHandler
32 | */
33 | @ThreadSafe
34 | public class InFlightRequestTracker {
35 |
36 | private final CompletableFuture terminationFuture = new CompletableFuture<>();
37 |
38 | private final Phaser phaser = new Phaser(1) {
39 | @Override
40 | protected boolean onAdvance(final int phase, final int registeredParties) {
41 | terminationFuture.complete(null);
42 | return true;
43 | }
44 | };
45 |
46 | /**
47 | * Registers an in-flight request.
48 | */
49 | public void registerRequest() {
50 | phaser.register();
51 | }
52 |
53 | /**
54 | * Deregisters an in-flight request.
55 | */
56 | public void deregisterRequest() {
57 | phaser.arriveAndDeregister();
58 | }
59 |
60 | /**
61 | * Returns a future that completes when the in-flight requests that were registered prior to
62 | * calling this method are deregistered.
63 | */
64 | public CompletableFuture awaitAsync() {
65 | phaser.arriveAndDeregister();
66 | return terminationFuture;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/JobCancelHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.JobCancelResponseBody;
22 | import com.ververica.flink.table.gateway.rest.message.JobIdPathParameter;
23 | import com.ververica.flink.table.gateway.rest.message.SessionIdPathParameter;
24 | import com.ververica.flink.table.gateway.rest.message.SessionJobMessageParameters;
25 |
26 | import org.apache.flink.runtime.rest.HttpMethodWrapper;
27 | import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
28 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
29 |
30 | import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
31 |
32 | /**
33 | * Message headers for canceling a Flink job.
34 | */
35 | public class JobCancelHeaders
36 | implements MessageHeaders {
37 |
38 | private static final JobCancelHeaders INSTANCE = new JobCancelHeaders();
39 |
40 | public static final String URL = "/sessions/:" + SessionIdPathParameter.KEY +
41 | "/jobs/:" + JobIdPathParameter.KEY;
42 |
43 | private JobCancelHeaders() {
44 | }
45 |
46 | @Override
47 | public Class getResponseClass() {
48 | return JobCancelResponseBody.class;
49 | }
50 |
51 | @Override
52 | public HttpResponseStatus getResponseStatusCode() {
53 | return HttpResponseStatus.OK;
54 | }
55 |
56 | @Override
57 | public String getDescription() {
58 | return "Cancels a running job.";
59 | }
60 |
61 | @Override
62 | public Class getRequestClass() {
63 | return EmptyRequestBody.class;
64 | }
65 |
66 | @Override
67 | public SessionJobMessageParameters getUnresolvedMessageParameters() {
68 | return new SessionJobMessageParameters();
69 | }
70 |
71 | @Override
72 | public HttpMethodWrapper getHttpMethod() {
73 | return HttpMethodWrapper.DELETE;
74 | }
75 |
76 | @Override
77 | public String getTargetRestEndpointURL() {
78 | return URL;
79 | }
80 |
81 | public static JobCancelHeaders getInstance() {
82 | return INSTANCE;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/JobStatusHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.JobIdPathParameter;
22 | import com.ververica.flink.table.gateway.rest.message.JobStatusResponseBody;
23 | import com.ververica.flink.table.gateway.rest.message.SessionIdPathParameter;
24 | import com.ververica.flink.table.gateway.rest.message.SessionJobMessageParameters;
25 |
26 | import org.apache.flink.runtime.rest.HttpMethodWrapper;
27 | import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
28 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
29 |
30 | import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
31 |
32 | /**
33 | * Messages headers for getting job status.
34 | */
35 | public class JobStatusHeaders
36 | implements MessageHeaders {
37 |
38 | private static final JobStatusHeaders INSTANCE = new JobStatusHeaders();
39 |
40 | public static final String URL = "/sessions/:" + SessionIdPathParameter.KEY +
41 | "/jobs/:" + JobIdPathParameter.KEY + "/status";
42 |
43 | private JobStatusHeaders() {
44 | }
45 |
46 | @Override
47 | public Class getResponseClass() {
48 | return JobStatusResponseBody.class;
49 | }
50 |
51 | @Override
52 | public HttpResponseStatus getResponseStatusCode() {
53 | return HttpResponseStatus.OK;
54 | }
55 |
56 | @Override
57 | public String getDescription() {
58 | return "get job status.";
59 | }
60 |
61 | @Override
62 | public Class getRequestClass() {
63 | return EmptyRequestBody.class;
64 | }
65 |
66 | @Override
67 | public SessionJobMessageParameters getUnresolvedMessageParameters() {
68 | return new SessionJobMessageParameters();
69 | }
70 |
71 | @Override
72 | public HttpMethodWrapper getHttpMethod() {
73 | return HttpMethodWrapper.GET;
74 | }
75 |
76 | @Override
77 | public String getTargetRestEndpointURL() {
78 | return URL;
79 | }
80 |
81 | public static JobStatusHeaders getInstance() {
82 | return INSTANCE;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/SessionCloseHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.SessionCloseResponseBody;
22 | import com.ververica.flink.table.gateway.rest.message.SessionIdPathParameter;
23 | import com.ververica.flink.table.gateway.rest.message.SessionMessageParameters;
24 |
25 | import org.apache.flink.runtime.rest.HttpMethodWrapper;
26 | import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
27 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
28 |
29 | import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
30 |
31 | /**
32 | * Message headers for closing a session.
33 | */
34 | public class SessionCloseHeaders
35 | implements MessageHeaders {
36 |
37 | private static final SessionCloseHeaders INSTANCE = new SessionCloseHeaders();
38 |
39 | public static final String URL = "/sessions/:" + SessionIdPathParameter.KEY;
40 |
41 | private SessionCloseHeaders() {
42 | }
43 |
44 | @Override
45 | public Class getResponseClass() {
46 | return SessionCloseResponseBody.class;
47 | }
48 |
49 | @Override
50 | public HttpResponseStatus getResponseStatusCode() {
51 | return HttpResponseStatus.OK;
52 | }
53 |
54 | @Override
55 | public String getDescription() {
56 | return "Closes the specific session.";
57 | }
58 |
59 | @Override
60 | public Class getRequestClass() {
61 | return EmptyRequestBody.class;
62 | }
63 |
64 | @Override
65 | public SessionMessageParameters getUnresolvedMessageParameters() {
66 | return new SessionMessageParameters();
67 | }
68 |
69 | @Override
70 | public HttpMethodWrapper getHttpMethod() {
71 | return HttpMethodWrapper.DELETE;
72 | }
73 |
74 | @Override
75 | public String getTargetRestEndpointURL() {
76 | return URL;
77 | }
78 |
79 | public static SessionCloseHeaders getInstance() {
80 | return INSTANCE;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/SessionCreateHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.SessionCreateRequestBody;
22 | import com.ververica.flink.table.gateway.rest.message.SessionCreateResponseBody;
23 |
24 | import org.apache.flink.runtime.rest.HttpMethodWrapper;
25 | import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
26 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
27 |
28 | import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
29 |
30 | /**
31 | * Message headers for creating a session.
32 | */
33 | public class SessionCreateHeaders
34 | implements MessageHeaders {
35 |
36 | private static final SessionCreateHeaders INSTANCE = new SessionCreateHeaders();
37 |
38 | public static final String URL = "/sessions";
39 |
40 | private SessionCreateHeaders() {
41 | }
42 |
43 | @Override
44 | public Class getResponseClass() {
45 | return SessionCreateResponseBody.class;
46 | }
47 |
48 | @Override
49 | public HttpResponseStatus getResponseStatusCode() {
50 | return HttpResponseStatus.OK;
51 | }
52 |
53 | @Override
54 | public String getDescription() {
55 | return "Creates a new session with a specific planner and execution type. " +
56 | "Specific properties can be given for current session " +
57 | "which will override the default properties of gateway.";
58 | }
59 |
60 | @Override
61 | public Class getRequestClass() {
62 | return SessionCreateRequestBody.class;
63 | }
64 |
65 | @Override
66 | public EmptyMessageParameters getUnresolvedMessageParameters() {
67 | return EmptyMessageParameters.getInstance();
68 | }
69 |
70 | @Override
71 | public HttpMethodWrapper getHttpMethod() {
72 | return HttpMethodWrapper.POST;
73 | }
74 |
75 | @Override
76 | public String getTargetRestEndpointURL() {
77 | return URL;
78 | }
79 |
80 | public static SessionCreateHeaders getInstance() {
81 | return INSTANCE;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/handler/SessionHeartbeatHeaders.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.handler;
20 |
21 | import com.ververica.flink.table.gateway.rest.message.SessionIdPathParameter;
22 | import com.ververica.flink.table.gateway.rest.message.SessionMessageParameters;
23 |
24 | import org.apache.flink.runtime.rest.HttpMethodWrapper;
25 | import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
26 | import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
27 | import org.apache.flink.runtime.rest.messages.MessageHeaders;
28 |
29 | import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
30 |
31 | /**
32 | * Message headers for triggering session heartbeat.
33 | */
34 | public class SessionHeartbeatHeaders
35 | implements MessageHeaders {
36 |
37 | private static final SessionHeartbeatHeaders INSTANCE = new SessionHeartbeatHeaders();
38 |
39 | public static final String URL = "/sessions/:" + SessionIdPathParameter.KEY + "/heartbeat";
40 |
41 | private SessionHeartbeatHeaders() {
42 | }
43 |
44 | @Override
45 | public Class getResponseClass() {
46 | return EmptyResponseBody.class;
47 | }
48 |
49 | @Override
50 | public HttpResponseStatus getResponseStatusCode() {
51 | return HttpResponseStatus.OK;
52 | }
53 |
54 | @Override
55 | public String getDescription() {
56 | return "Triggers session heartbeat";
57 | }
58 |
59 | @Override
60 | public Class getRequestClass() {
61 | return EmptyRequestBody.class;
62 | }
63 |
64 | @Override
65 | public SessionMessageParameters getUnresolvedMessageParameters() {
66 | return new SessionMessageParameters();
67 | }
68 |
69 | @Override
70 | public HttpMethodWrapper getHttpMethod() {
71 | return HttpMethodWrapper.POST;
72 | }
73 |
74 | @Override
75 | public String getTargetRestEndpointURL() {
76 | return URL;
77 | }
78 |
79 | public static SessionHeartbeatHeaders getInstance() {
80 | return INSTANCE;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/GetInfoResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.ResponseBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
25 |
26 | /**
27 | * {@link ResponseBody} for getting info.
28 | */
29 | @JsonInclude(JsonInclude.Include.NON_NULL)
30 | public class GetInfoResponseBody implements ResponseBody {
31 |
32 | private static final String FIELD_NAME_PRODUCT_NAME = "product_name";
33 | private static final String FIELD_NAME_FLINK_VERSION = "version";
34 |
35 | @JsonProperty(FIELD_NAME_PRODUCT_NAME)
36 | private final String productName;
37 |
38 | @JsonProperty(FIELD_NAME_FLINK_VERSION)
39 | private final String flinkVersion;
40 |
41 | public GetInfoResponseBody(
42 | @JsonProperty(FIELD_NAME_PRODUCT_NAME) String productName,
43 | @JsonProperty(FIELD_NAME_FLINK_VERSION) String flinkVersion) {
44 | this.productName = productName;
45 | this.flinkVersion = flinkVersion;
46 | }
47 |
48 | public String getProductName() {
49 | return productName;
50 | }
51 |
52 | public String getFlinkVersion() {
53 | return flinkVersion;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/JobCancelResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.ResponseBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
25 |
26 | /**
27 | * {@link ResponseBody} for canceling a Flink job.
28 | */
29 | @JsonInclude(JsonInclude.Include.NON_NULL)
30 | public class JobCancelResponseBody implements ResponseBody {
31 |
32 | private static final String FIELD_NAME_STATUS = "status";
33 |
34 | @JsonProperty(FIELD_NAME_STATUS)
35 | private String status;
36 |
37 | public JobCancelResponseBody(@JsonProperty(FIELD_NAME_STATUS) String status) {
38 | this.status = status;
39 | }
40 |
41 | public String getStatus() {
42 | return status;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/JobIdPathParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.api.common.JobID;
22 | import org.apache.flink.runtime.rest.messages.ConversionException;
23 | import org.apache.flink.runtime.rest.messages.MessagePathParameter;
24 |
25 | /**
26 | * {@link MessagePathParameter} for job id.
27 | */
28 | public class JobIdPathParameter extends MessagePathParameter {
29 |
30 | public static final String KEY = "job_id";
31 |
32 | public JobIdPathParameter() {
33 | super(KEY);
34 | }
35 |
36 | @Override
37 | protected JobID convertFromString(String value) throws ConversionException {
38 | try {
39 | return JobID.fromHexString(value);
40 | } catch (IllegalArgumentException iae) {
41 | throw new ConversionException("Not a valid job ID: " + value, iae);
42 | }
43 | }
44 |
45 | @Override
46 | protected String convertToString(JobID value) {
47 | return value.toHexString();
48 | }
49 |
50 | @Override
51 | public String getDescription() {
52 | return "A string that identifies a job.";
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/JobStatusResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.ResponseBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
25 |
26 | /**
27 | * {@link ResponseBody} for getting job status.
28 | */
29 | @JsonInclude(JsonInclude.Include.NON_NULL)
30 | public class JobStatusResponseBody implements ResponseBody {
31 |
32 | private static final String FIELD_NAME_STATUS = "status";
33 |
34 | @JsonProperty(FIELD_NAME_STATUS)
35 | private String status;
36 |
37 | public JobStatusResponseBody(@JsonProperty(FIELD_NAME_STATUS) String status) {
38 | this.status = status;
39 | }
40 |
41 | public String getStatus() {
42 | return status;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/ResultFetchMessageParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.api.common.JobID;
22 | import org.apache.flink.runtime.rest.messages.MessageParameters;
23 | import org.apache.flink.runtime.rest.messages.MessagePathParameter;
24 | import org.apache.flink.runtime.rest.messages.MessageQueryParameter;
25 |
26 | import java.util.Arrays;
27 | import java.util.Collection;
28 | import java.util.Collections;
29 |
30 | /**
31 | * {@link MessageParameters} for fetching job result.
32 | */
33 | public class ResultFetchMessageParameters extends MessageParameters {
34 |
35 | private final SessionIdPathParameter sessionIdPathParameter = new SessionIdPathParameter();
36 | private final JobIdPathParameter jobIdPathParameter = new JobIdPathParameter();
37 | private final ResultTokenPathParameter resultTokenPathParameter = new ResultTokenPathParameter();
38 |
39 | public ResultFetchMessageParameters() {
40 | // nothing to resolve
41 | }
42 |
43 | public ResultFetchMessageParameters(String sessionId, JobID jobId, long token) {
44 | sessionIdPathParameter.resolve(sessionId);
45 | jobIdPathParameter.resolve(jobId);
46 | resultTokenPathParameter.resolve(token);
47 | }
48 |
49 | @Override
50 | public Collection> getPathParameters() {
51 | return Arrays.asList(sessionIdPathParameter, jobIdPathParameter, resultTokenPathParameter);
52 | }
53 |
54 | @Override
55 | public Collection> getQueryParameters() {
56 | return Collections.emptyList();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/ResultFetchRequestBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.RequestBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
25 |
26 | import javax.annotation.Nullable;
27 |
28 | /**
29 | * {@link RequestBody} for fetching job result.
30 | */
31 | @JsonInclude(JsonInclude.Include.NON_NULL)
32 | public class ResultFetchRequestBody implements RequestBody {
33 |
34 | private static final String FIELD_NAME_MAX_FETCH_SIZE = "max_fetch_size";
35 |
36 | @JsonProperty(FIELD_NAME_MAX_FETCH_SIZE)
37 | @Nullable
38 | private final Integer maxFetchSize;
39 |
40 | public ResultFetchRequestBody(
41 | @Nullable @JsonProperty(FIELD_NAME_MAX_FETCH_SIZE) Integer maxFetchSize) {
42 | this.maxFetchSize = maxFetchSize;
43 | }
44 |
45 | @Nullable
46 | public Integer getMaxFetchSize() {
47 | return maxFetchSize;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/ResultFetchResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
22 |
23 | import org.apache.flink.runtime.rest.messages.ResponseBody;
24 |
25 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
26 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
27 |
28 | import javax.annotation.Nullable;
29 |
30 | import java.util.List;
31 |
32 | /**
33 | * {@link ResponseBody} for fetching job result.
34 | */
35 | @JsonInclude(JsonInclude.Include.NON_NULL)
36 | public class ResultFetchResponseBody implements ResponseBody {
37 |
38 | private static final String FIELD_NAME_RESULTS = "results";
39 | private static final String FIELD_NAME_NEXT_RESULT_URI = "next_result_uri";
40 |
41 | @JsonProperty(FIELD_NAME_RESULTS)
42 | @Nullable
43 | private List results;
44 |
45 | @JsonProperty(FIELD_NAME_NEXT_RESULT_URI)
46 | @Nullable
47 | private String nextResultUri;
48 |
49 | public ResultFetchResponseBody(
50 | @Nullable @JsonProperty(FIELD_NAME_RESULTS) List results,
51 | @Nullable @JsonProperty(FIELD_NAME_NEXT_RESULT_URI) String nextResultUri) {
52 | this.results = results;
53 | this.nextResultUri = nextResultUri;
54 | }
55 |
56 | @Nullable
57 | public List getResults() {
58 | return results;
59 | }
60 |
61 | @Nullable
62 | public String getNextResultUri() {
63 | return nextResultUri;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/ResultTokenPathParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.ConversionException;
22 | import org.apache.flink.runtime.rest.messages.MessagePathParameter;
23 |
24 | /**
25 | * {@link MessagePathParameter} for token.
26 | */
27 | public class ResultTokenPathParameter extends MessagePathParameter {
28 |
29 | public static final String KEY = "token";
30 |
31 | public ResultTokenPathParameter() {
32 | super(KEY);
33 | }
34 |
35 | @Override
36 | protected Long convertFromString(String value) throws ConversionException {
37 | try {
38 | return Long.valueOf(value);
39 | } catch (NumberFormatException e) {
40 | throw new ConversionException("Invalid token " + value + ". Token must be a long value.");
41 | }
42 | }
43 |
44 | @Override
45 | protected String convertToString(Long value) {
46 | return value.toString();
47 | }
48 |
49 | @Override
50 | public String getDescription() {
51 | return "A Long that identifies a toke to fetch job result.";
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/SessionCloseResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.ResponseBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
25 |
26 | /**
27 | * {@link ResponseBody} for closing a session.
28 | */
29 | @JsonInclude(JsonInclude.Include.NON_NULL)
30 | public class SessionCloseResponseBody implements ResponseBody {
31 |
32 | private static final String FIELD_NAME_STATUS = "status";
33 |
34 | @JsonProperty(FIELD_NAME_STATUS)
35 | private String status;
36 |
37 | public SessionCloseResponseBody(@JsonProperty(FIELD_NAME_STATUS) String status) {
38 | this.status = status;
39 | }
40 |
41 | public String getStatus() {
42 | return status;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/SessionCreateResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.ResponseBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
25 |
26 | /**
27 | * {@link ResponseBody} for creating a session.
28 | */
29 | @JsonInclude(JsonInclude.Include.NON_NULL)
30 | public class SessionCreateResponseBody implements ResponseBody {
31 |
32 | private static final String FIELD_SESSION_ID = "session_id";
33 |
34 | @JsonProperty(FIELD_SESSION_ID)
35 | private String sessionId;
36 |
37 | public SessionCreateResponseBody(
38 | @JsonProperty(FIELD_SESSION_ID) String sessionId) {
39 | this.sessionId = sessionId;
40 | }
41 |
42 | public String getSessionId() {
43 | return sessionId;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/SessionIdPathParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import com.ververica.flink.table.gateway.rest.session.SessionID;
22 |
23 | import org.apache.flink.runtime.rest.messages.ConversionException;
24 | import org.apache.flink.runtime.rest.messages.MessagePathParameter;
25 |
26 | /**
27 | * {@link MessagePathParameter} for session id.
28 | */
29 | public class SessionIdPathParameter extends MessagePathParameter {
30 |
31 | public static final String KEY = "session_id";
32 |
33 | public SessionIdPathParameter() {
34 | super(KEY);
35 | }
36 |
37 | @Override
38 | protected String convertFromString(String value) throws ConversionException {
39 | try {
40 | SessionID.fromHexString(value);
41 | // TODO return SessionID
42 | return value;
43 | } catch (IllegalArgumentException iae) {
44 | throw new ConversionException("Not a valid session ID: " + value, iae);
45 | }
46 | }
47 |
48 | @Override
49 | protected String convertToString(String value) {
50 | return value;
51 | }
52 |
53 | @Override
54 | public String getDescription() {
55 | return "A string that identifies a session.";
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/SessionJobMessageParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.api.common.JobID;
22 | import org.apache.flink.runtime.rest.messages.MessageParameters;
23 | import org.apache.flink.runtime.rest.messages.MessagePathParameter;
24 | import org.apache.flink.runtime.rest.messages.MessageQueryParameter;
25 |
26 | import java.util.Arrays;
27 | import java.util.Collection;
28 | import java.util.Collections;
29 |
30 | /**
31 | * {@link MessageParameters} for session id and job id.
32 | */
33 | public class SessionJobMessageParameters extends MessageParameters {
34 |
35 | private final SessionIdPathParameter sessionIdPathParameter = new SessionIdPathParameter();
36 | private final JobIdPathParameter jobIdPathParameter = new JobIdPathParameter();
37 |
38 | public SessionJobMessageParameters() {
39 | // nothing to resolve
40 | }
41 |
42 | public SessionJobMessageParameters(String sessionId, JobID jobId) {
43 | sessionIdPathParameter.resolve(sessionId);
44 | jobIdPathParameter.resolve(jobId);
45 | }
46 |
47 | @Override
48 | public Collection> getPathParameters() {
49 | return Arrays.asList(
50 | sessionIdPathParameter,
51 | jobIdPathParameter);
52 | }
53 |
54 | @Override
55 | public Collection> getQueryParameters() {
56 | return Collections.emptyList();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/SessionMessageParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.MessageParameters;
22 | import org.apache.flink.runtime.rest.messages.MessagePathParameter;
23 | import org.apache.flink.runtime.rest.messages.MessageQueryParameter;
24 |
25 | import java.util.Collection;
26 | import java.util.Collections;
27 |
28 | /**
29 | * {@link MessageParameters} for session id.
30 | */
31 | public class SessionMessageParameters extends MessageParameters {
32 |
33 | private final SessionIdPathParameter sessionIDPathParameter = new SessionIdPathParameter();
34 |
35 | public SessionMessageParameters() {
36 | // nothing to resolve
37 | }
38 |
39 | public SessionMessageParameters(String sessionId) {
40 | sessionIDPathParameter.resolve(sessionId);
41 | }
42 |
43 | @Override
44 | public Collection> getPathParameters() {
45 | return Collections.singletonList(sessionIDPathParameter);
46 | }
47 |
48 | @Override
49 | public Collection> getQueryParameters() {
50 | return Collections.emptyList();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/StatementExecuteRequestBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import org.apache.flink.runtime.rest.messages.RequestBody;
22 |
23 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnore;
24 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
25 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
26 |
27 | import javax.annotation.Nullable;
28 |
29 | /**
30 | * {@link RequestBody} for executing a statement.
31 | */
32 | @JsonInclude(JsonInclude.Include.NON_NULL)
33 | public class StatementExecuteRequestBody implements RequestBody {
34 |
35 | private static final String FIELD_STATEMENT = "statement";
36 | private static final String FIELD_EXECUTION_TIMEOUT = "execution_timeout";
37 |
38 | @JsonProperty(FIELD_STATEMENT)
39 | @Nullable
40 | private String statement;
41 |
42 | @JsonProperty(FIELD_EXECUTION_TIMEOUT)
43 | @Nullable
44 | private Long executionTimeout;
45 |
46 | public StatementExecuteRequestBody(
47 | @Nullable @JsonProperty(FIELD_STATEMENT) String statement,
48 | @Nullable @JsonProperty(FIELD_EXECUTION_TIMEOUT) Long executionTimeout) {
49 | this.statement = statement;
50 | this.executionTimeout = executionTimeout;
51 | }
52 |
53 | @Nullable
54 | @JsonIgnore
55 | public String getStatement() {
56 | return statement;
57 | }
58 |
59 | @Nullable
60 | @JsonIgnore
61 | public Long getExecutionTimeout() {
62 | return executionTimeout;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/message/StatementExecuteResponseBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.message;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
22 |
23 | import org.apache.flink.runtime.rest.messages.ResponseBody;
24 |
25 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
26 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
27 |
28 | import java.util.List;
29 |
30 | /**
31 | * {@link ResponseBody} for executing a statement.
32 | */
33 | @JsonInclude(JsonInclude.Include.NON_NULL)
34 | public class StatementExecuteResponseBody implements ResponseBody {
35 |
36 | private static final String FIELD_NAME_RESULT = "results";
37 | private static final String FIELD_NAME_STATEMENT_TYPE = "statement_types";
38 |
39 | @JsonProperty(FIELD_NAME_RESULT)
40 | private final List results;
41 |
42 | @JsonProperty(FIELD_NAME_STATEMENT_TYPE)
43 | private final List statementTypes;
44 |
45 | public StatementExecuteResponseBody(
46 | @JsonProperty(FIELD_NAME_RESULT) List results,
47 | @JsonProperty(FIELD_NAME_STATEMENT_TYPE) List statementTypes) {
48 | this.results = results;
49 | this.statementTypes = statementTypes;
50 | }
51 |
52 | public List getResults() {
53 | return results;
54 | }
55 |
56 | public List getStatementTypes() {
57 | return statementTypes;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/result/ConstantNames.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.result;
20 |
21 | /**
22 | * Constant column names.
23 | */
24 | public class ConstantNames {
25 |
26 | // for statement execution
27 | public static final String JOB_ID = "job_id";
28 |
29 | // for results with SUCCESS result kind
30 | public static final String RESULT = "result";
31 | public static final String OK = "OK";
32 |
33 | public static final String SHOW_MODULES_RESULT = "modules";
34 |
35 | public static final String SHOW_CURRENT_CATALOG_RESULT = "catalog";
36 |
37 | public static final String SHOW_CATALOGS_RESULT = "catalogs";
38 |
39 | public static final String SHOW_CURRENT_DATABASE_RESULT = "database";
40 |
41 | public static final String SHOW_DATABASES_RESULT = "databases";
42 |
43 | public static final String SHOW_FUNCTIONS_RESULT = "functions";
44 |
45 | public static final String EXPLAIN_RESULT = "explanation";
46 |
47 | public static final String DESCRIBE_NAME = "name";
48 | public static final String DESCRIBE_TYPE = "type";
49 | public static final String DESCRIBE_NULL = "null";
50 | public static final String DESCRIBE_KEY = "key";
51 | public static final String DESCRIBE_COMPUTED_COLUMN = "computed_column";
52 | public static final String DESCRIBE_WATERMARK = "watermark";
53 |
54 | public static final String SHOW_TABLES_RESULT = "tables";
55 |
56 | public static final String SHOW_VIEWS_RESULT = "views";
57 |
58 | public static final String SET_KEY = "key";
59 | public static final String SET_VALUE = "value";
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/rest/result/ResultKind.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.rest.result;
20 |
21 | /**
22 | * ResultKind defines the types of the result.
23 | */
24 | public enum ResultKind {
25 | // for DDL, DCL and statements with a simple "OK"
26 | SUCCESS,
27 |
28 | // rows with important content are available (DML, DQL)
29 | SUCCESS_WITH_CONTENT
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/result/AbstractResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.result;
20 |
21 | /**
22 | * Basic result of a table program that has been submitted to a cluster.
23 | *
24 | * @param cluster id to which this result belongs to
25 | */
26 | public abstract class AbstractResult implements Result {
27 |
28 | protected C clusterId;
29 | protected String webInterfaceUrl;
30 |
31 | @Override
32 | public void setClusterInformation(C clusterId, String webInterfaceUrl) {
33 | if (this.clusterId != null || this.webInterfaceUrl != null) {
34 | throw new IllegalStateException("Cluster information is already present.");
35 | }
36 | this.clusterId = clusterId;
37 | this.webInterfaceUrl = webInterfaceUrl;
38 | }
39 |
40 | public C getClusterId() {
41 | if (this.clusterId == null) {
42 | throw new IllegalStateException("Cluster ID has not been set.");
43 | }
44 | return clusterId;
45 | }
46 |
47 | public String getWebInterfaceUrl() {
48 | if (this.webInterfaceUrl == null) {
49 | throw new IllegalStateException("Cluster web interface URL has not been set.");
50 | }
51 | return webInterfaceUrl;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/result/Result.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.result;
20 |
21 | import org.apache.flink.core.execution.JobClient;
22 | import org.apache.flink.table.sinks.TableSink;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * A result of a table program submission to a cluster.
28 | *
29 | * @param type of the cluster id to which this result belongs to
30 | * @param type of result data
31 | */
32 | public interface Result {
33 |
34 | /**
35 | * Sets the cluster information of the cluster this result comes from. This method should only be called once.
36 | */
37 | void setClusterInformation(C clusterId, String webInterfaceUrl);
38 |
39 | /**
40 | * Starts the table program using the given deployer and monitors it's execution.
41 | */
42 | void startRetrieval(JobClient jobClient);
43 |
44 | /**
45 | * Retrieves the available result records.
46 | */
47 | TypedResult> retrieveChanges();
48 |
49 | /**
50 | * Returns the table sink required by this result type.
51 | */
52 | TableSink> getTableSink();
53 |
54 | /**
55 | * Closes the retrieval and all involved threads.
56 | */
57 | void close();
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/result/ResultDescriptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.result;
20 |
21 | import org.apache.flink.core.execution.JobClient;
22 | import org.apache.flink.table.api.TableSchema;
23 |
24 | /**
25 | * Describes a result to be expected from a table program.
26 | */
27 | public class ResultDescriptor {
28 |
29 | private final Result, ?> result;
30 |
31 | private boolean isChangelogResult;
32 |
33 | private final TableSchema resultSchema;
34 |
35 | private final JobClient jobClient;
36 |
37 | public ResultDescriptor(Result, ?> result, boolean isChangelogResult, TableSchema resultSchema, JobClient jobClient) {
38 | this.result = result;
39 | this.isChangelogResult = isChangelogResult;
40 | this.resultSchema = resultSchema;
41 | this.jobClient = jobClient;
42 | }
43 |
44 | public Result, ?> getResult() {
45 | return result;
46 | }
47 |
48 | public boolean isChangelogResult() {
49 | return isChangelogResult;
50 | }
51 |
52 | public TableSchema getResultSchema() {
53 | return resultSchema;
54 | }
55 |
56 | public JobClient getJobClient() {
57 | return jobClient;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/result/TypedResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.result;
20 |
21 | import java.util.Objects;
22 |
23 | /**
24 | * Result with an attached type (actual payload, EOS, etc.).
25 | *
26 | * @param
type of payload
27 | */
28 | public class TypedResult
{
29 |
30 | private ResultType type;
31 |
32 | private P payload;
33 |
34 | private TypedResult(ResultType type, P payload) {
35 | this.type = type;
36 | this.payload = payload;
37 | }
38 |
39 | public ResultType getType() {
40 | return type;
41 | }
42 |
43 | public P getPayload() {
44 | return payload;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "TypedResult<" + type + ">";
50 | }
51 |
52 | @Override
53 | public boolean equals(Object o) {
54 | if (this == o) {
55 | return true;
56 | }
57 | if (o == null || getClass() != o.getClass()) {
58 | return false;
59 | }
60 | TypedResult> that = (TypedResult>) o;
61 | return type == that.type && Objects.equals(payload, that.payload);
62 | }
63 |
64 | @Override
65 | public int hashCode() {
66 | return Objects.hash(type, payload);
67 | }
68 |
69 | // --------------------------------------------------------------------------------------------
70 |
71 | public static TypedResult empty() {
72 | return new TypedResult<>(ResultType.EMPTY, null);
73 | }
74 |
75 | public static TypedResult payload(T payload) {
76 | return new TypedResult<>(ResultType.PAYLOAD, payload);
77 | }
78 |
79 | public static TypedResult endOfStream() {
80 | return new TypedResult<>(ResultType.EOS, null);
81 | }
82 |
83 | // --------------------------------------------------------------------------------------------
84 |
85 | /**
86 | * Result types.
87 | */
88 | public enum ResultType {
89 | PAYLOAD,
90 | EMPTY,
91 | EOS
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/utils/EnvironmentUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.utils;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 |
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 |
26 | import java.io.IOException;
27 | import java.net.URL;
28 |
29 | /**
30 | * Utility class for reading environment file.
31 | */
32 | public class EnvironmentUtil {
33 | private static final Logger LOG = LoggerFactory.getLogger(EnvironmentUtil.class);
34 |
35 | public static Environment readEnvironment(URL envUrl) {
36 | // use an empty environment by default
37 | if (envUrl == null) {
38 | System.out.println("No session environment specified.");
39 | return new Environment();
40 | }
41 |
42 | System.out.println("Reading configuration from: " + envUrl);
43 | LOG.info("Using configuration file: {}", envUrl);
44 | try {
45 | return Environment.parse(envUrl);
46 | } catch (IOException e) {
47 | throw new SqlGatewayException("Could not read configuration file at: " + envUrl, e);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/utils/SqlExecutionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.utils;
20 |
21 | /**
22 | * Exception thrown during the execution of SQL statements.
23 | */
24 | public class SqlExecutionException extends RuntimeException {
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | public SqlExecutionException(String message) {
29 | super(message);
30 | }
31 |
32 | public SqlExecutionException(String message, Throwable e) {
33 | super(message, e);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/ververica/flink/table/gateway/utils/SqlGatewayException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.utils;
20 |
21 | /**
22 | * Exception thrown in gateway.
23 | */
24 | public class SqlGatewayException extends RuntimeException {
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | public SqlGatewayException(String msg) {
29 | super(msg);
30 | }
31 |
32 | public SqlGatewayException(String msg, Throwable cause) {
33 | super(msg, cause);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/assembly/test-random-source.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 | test-jar
23 |
24 | jar
25 |
26 | false
27 |
28 |
29 |
30 |
31 | src/test/resources/service-file/test-random-source-file
32 | META-INF/services
33 | org.apache.flink.table.factories.TableFactory
34 | 0644
35 |
36 |
37 |
38 |
39 |
40 |
41 | ${project.build.directory}/test-classes/com/ververica/flink/table/gateway/source/random
42 | com/ververica/flink/table/gateway/source/random
43 | 0644
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/test/assembly/test-table-factories.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 | test-jar
23 |
24 | jar
25 |
26 | false
27 |
28 |
29 |
30 | src/test/resources/service-file/test-factory-services-file
31 | META-INF/services
32 | org.apache.flink.table.factories.TableFactory
33 | 0755
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/CreateViewOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
22 |
23 | import org.junit.Test;
24 |
25 | import static org.junit.Assert.assertArrayEquals;
26 | import static org.junit.Assert.assertEquals;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | /**
30 | * Tests for {@link CreateViewOperation}.
31 | */
32 | public class CreateViewOperationTest extends OperationTestBase {
33 |
34 | @Test
35 | public void testCreateView() {
36 | CreateViewOperation operation = new CreateViewOperation(context, "MyView1", "select 1 + 1");
37 | ResultSet resultSet = operation.execute();
38 | assertEquals(OperationUtil.OK, resultSet);
39 |
40 | String[] tables = context.getExecutionContext().getTableEnvironment().listTables();
41 | assertArrayEquals(new String[] { "MyView1" }, tables);
42 | assertTrue(context.getExecutionContext().getEnvironment().getTables().containsKey("MyView1"));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ExplainOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
23 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
24 | import com.ververica.flink.table.gateway.utils.ResourceFileUtils;
25 |
26 | import org.junit.Test;
27 |
28 | import java.util.HashMap;
29 | import java.util.Map;
30 |
31 | /**
32 | * Tests for {@link ExplainOperation}.
33 | */
34 | public class ExplainOperationTest extends OperationTestBase {
35 |
36 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
37 |
38 | @Override
39 | protected Environment getSessionEnvironment() throws Exception {
40 | final Map replaceVars = new HashMap<>();
41 | replaceVars.put("$VAR_PLANNER", "old");
42 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
43 | replaceVars.put("$VAR_UPDATE_MODE", "");
44 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
45 | }
46 |
47 | @Test
48 | public void testExplain() {
49 | ExplainOperation operation = new ExplainOperation(context, "select * from TableNumber1");
50 | ResultSet resultSet = operation.execute();
51 |
52 | String expectedExplain = ResourceFileUtils.readAll(
53 | "plan/explain-operation-test.test-explain.expected");
54 | OperationTestUtils.compareExplainResult(expectedExplain, resultSet);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/OperationTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.config.entries.ExecutionEntry;
23 | import com.ververica.flink.table.gateway.context.DefaultContext;
24 | import com.ververica.flink.table.gateway.context.SessionContext;
25 | import com.ververica.flink.table.gateway.rest.session.SessionID;
26 |
27 | import org.apache.flink.client.cli.DefaultCLI;
28 | import org.apache.flink.client.deployment.DefaultClusterClientServiceLoader;
29 | import org.apache.flink.configuration.Configuration;
30 |
31 | import org.junit.Before;
32 |
33 | import java.util.Collections;
34 | import java.util.HashMap;
35 | import java.util.Map;
36 |
37 | /**
38 | * Operation test base.
39 | */
40 | public class OperationTestBase {
41 |
42 | protected SessionContext context;
43 |
44 | @Before
45 | public void setup() throws Exception {
46 | context = new SessionContext(
47 | "test-session",
48 | SessionID.generate().toString(),
49 | getSessionEnvironment(),
50 | getDefaultContext());
51 | }
52 |
53 | protected DefaultContext getDefaultContext() {
54 | return new DefaultContext(
55 | new Environment(),
56 | Collections.emptyList(),
57 | new Configuration(),
58 | new DefaultCLI(new Configuration()),
59 | new DefaultClusterClientServiceLoader());
60 | }
61 |
62 | protected Environment getSessionEnvironment() throws Exception {
63 | Map newProperties = new HashMap<>();
64 | newProperties.put(Environment.EXECUTION_ENTRY + "." + ExecutionEntry.EXECUTION_PLANNER, "blink");
65 | newProperties.put(Environment.EXECUTION_ENTRY + "." + ExecutionEntry.EXECUTION_TYPE, "batch");
66 | return Environment.enrich(new Environment(), newProperties, Collections.emptyMap());
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/OperationTestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
22 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
23 |
24 | import static org.junit.Assert.assertEquals;
25 |
26 | /**
27 | * Utilities for running operation tests.
28 | */
29 | public class OperationTestUtils {
30 |
31 | public static void compareExplainResult(String expectedExplain, ResultSet resultSet) {
32 | assertEquals(resultSet.getResultKind(), ResultKind.SUCCESS_WITH_CONTENT);
33 | String actualExplain = resultSet.getData().get(0).getField(0).toString();
34 | assertEquals(
35 | replaceStageId(expectedExplain),
36 | replaceStageId(actualExplain));
37 | }
38 |
39 | private static String replaceStageId(String s) {
40 | return s.replaceAll("\\r\\n", "\n").replaceAll("Stage \\d+", "");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowCatalogsOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowCatalogsOperation}.
40 | */
41 | public class ShowCatalogsOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | replaceVars.put("$VAR_UPDATE_MODE", "");
51 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
52 | }
53 |
54 | @Test
55 | public void testShowCatalog() {
56 | ShowCatalogsOperation operation = new ShowCatalogsOperation(context);
57 | ResultSet resultSet = operation.execute();
58 |
59 | ResultSet expected = ResultSet.builder()
60 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
61 | .columns(ColumnInfo.create(ConstantNames.SHOW_CATALOGS_RESULT, new VarCharType(false, 15)))
62 | .data(Row.of("catalog1"), Row.of("default_catalog"), Row.of("simple-catalog"))
63 | .build();
64 | assertEquals(expected, resultSet);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowCurrentCatalogOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowCurrentCatalogOperation}.
40 | */
41 | public class ShowCurrentCatalogOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | replaceVars.put("$VAR_UPDATE_MODE", "");
51 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
52 | }
53 |
54 | @Test
55 | public void testShowCurrentCatalog() {
56 | context.getExecutionContext().getTableEnvironment().useCatalog("simple-catalog");
57 |
58 | ShowCurrentCatalogOperation operation = new ShowCurrentCatalogOperation(context);
59 | ResultSet resultSet = operation.execute();
60 |
61 | ResultSet expected = ResultSet.builder()
62 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
63 | .columns(ColumnInfo.create(ConstantNames.SHOW_CURRENT_CATALOG_RESULT, new VarCharType(false, 14)))
64 | .data(Row.of("simple-catalog"))
65 | .build();
66 | assertEquals(expected, resultSet);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowCurrentDatabaseOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowCurrentDatabaseOperation}.
40 | */
41 | public class ShowCurrentDatabaseOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | replaceVars.put("$VAR_UPDATE_MODE", "");
51 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
52 | }
53 |
54 | @Test
55 | public void testShowCurrentDatabase() {
56 | context.getExecutionContext().getTableEnvironment().useCatalog("catalog1");
57 | context.getExecutionContext().getTableEnvironment().useDatabase("default");
58 |
59 | ShowCurrentDatabaseOperation operation = new ShowCurrentDatabaseOperation(context);
60 | ResultSet resultSet = operation.execute();
61 |
62 | ResultSet expected = ResultSet.builder()
63 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
64 | .columns(ColumnInfo.create(ConstantNames.SHOW_CURRENT_DATABASE_RESULT, new VarCharType(false, 7)))
65 | .data(Row.of("default"))
66 | .build();
67 | assertEquals(expected, resultSet);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowDatabasesOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowDatabasesOperation}.
40 | */
41 | public class ShowDatabasesOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | replaceVars.put("$VAR_UPDATE_MODE", "");
51 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
52 | }
53 |
54 | @Test
55 | public void testShowDatabase() {
56 | context.getExecutionContext().getTableEnvironment().useCatalog("catalog1");
57 |
58 | ShowDatabasesOperation operation = new ShowDatabasesOperation(context);
59 | ResultSet resultSet = operation.execute();
60 |
61 | ResultSet expected = ResultSet.builder()
62 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
63 | .columns(ColumnInfo.create(ConstantNames.SHOW_DATABASES_RESULT, new VarCharType(false, 7)))
64 | .data(Row.of("default"))
65 | .build();
66 | assertEquals(expected, resultSet);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowFunctionsOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
22 |
23 | import org.junit.Test;
24 |
25 | import static org.junit.Assert.assertTrue;
26 |
27 | /**
28 | * Tests for {@link ShowFunctionsOperation}.
29 | */
30 | public class ShowFunctionsOperationTest extends OperationTestBase {
31 |
32 | @Test
33 | public void testShowFunction() {
34 | ShowFunctionsOperation operation = new ShowFunctionsOperation(context);
35 | ResultSet resultSet = operation.execute();
36 | assertTrue(resultSet.getData().size() > 0);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowModulesOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowModulesOperation}.
40 | */
41 | public class ShowModulesOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-modules.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
51 | }
52 |
53 | @Test
54 | public void testShowModule() {
55 | ShowModulesOperation operation = new ShowModulesOperation(context);
56 | ResultSet resultSet = operation.execute();
57 |
58 | ResultSet expected = ResultSet.builder()
59 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
60 | .columns(ColumnInfo.create(ConstantNames.SHOW_MODULES_RESULT, new VarCharType(false, 8)))
61 | .data(Row.of("core"), Row.of("mymodule"), Row.of("myhive"), Row.of("myhive2"))
62 | .build();
63 | assertEquals(expected, resultSet);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowTablesOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowTablesOperation}.
40 | */
41 | public class ShowTablesOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | replaceVars.put("$VAR_UPDATE_MODE", "");
51 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
52 | }
53 |
54 | @Test
55 | public void testShowTable() {
56 | ShowTablesOperation operation = new ShowTablesOperation(context);
57 | ResultSet resultSet = operation.execute();
58 |
59 | ResultSet expected = ResultSet.builder()
60 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
61 | .columns(
62 | ColumnInfo.create(ConstantNames.SHOW_TABLES_RESULT, new VarCharType(false, 15)))
63 | .data(
64 | Row.of("TableNumber1"),
65 | Row.of("TableNumber2"),
66 | Row.of("TableSourceSink"),
67 | Row.of("TestView1"),
68 | Row.of("TestView2"))
69 | .build();
70 |
71 | assertEquals(expected, resultSet);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/ShowViewsOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.rest.result.ColumnInfo;
23 | import com.ververica.flink.table.gateway.rest.result.ConstantNames;
24 | import com.ververica.flink.table.gateway.rest.result.ResultKind;
25 | import com.ververica.flink.table.gateway.rest.result.ResultSet;
26 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
27 |
28 | import org.apache.flink.table.types.logical.VarCharType;
29 | import org.apache.flink.types.Row;
30 |
31 | import org.junit.Test;
32 |
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | import static org.junit.Assert.assertEquals;
37 |
38 | /**
39 | * Tests for {@link ShowViewsOperation}.
40 | */
41 | public class ShowViewsOperationTest extends OperationTestBase {
42 |
43 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
44 |
45 | @Override
46 | protected Environment getSessionEnvironment() throws Exception {
47 | final Map replaceVars = new HashMap<>();
48 | replaceVars.put("$VAR_PLANNER", "old");
49 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
50 | replaceVars.put("$VAR_UPDATE_MODE", "");
51 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
52 | }
53 |
54 | @Test
55 | public void testShowView() {
56 | ShowViewsOperation operation = new ShowViewsOperation(context);
57 | ResultSet resultSet = operation.execute();
58 |
59 | ResultSet expected = ResultSet.builder()
60 | .resultKind(ResultKind.SUCCESS_WITH_CONTENT)
61 | .columns(
62 | ColumnInfo.create(ConstantNames.SHOW_VIEWS_RESULT, new VarCharType(false, 9)))
63 | .data(
64 | Row.of("TestView1"),
65 | Row.of("TestView2"))
66 | .build();
67 |
68 | assertEquals(expected, resultSet);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/UseCatalogOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
23 |
24 | import org.junit.Test;
25 |
26 | import java.util.HashMap;
27 | import java.util.Map;
28 |
29 | import static org.junit.Assert.assertEquals;
30 |
31 | /**
32 | * Tests for {@link UseCatalogOperation}.
33 | */
34 | public class UseCatalogOperationTest extends OperationTestBase {
35 |
36 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
37 |
38 | @Override
39 | protected Environment getSessionEnvironment() throws Exception {
40 | final Map replaceVars = new HashMap<>();
41 | replaceVars.put("$VAR_PLANNER", "old");
42 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
43 | replaceVars.put("$VAR_UPDATE_MODE", "");
44 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
45 | }
46 |
47 | @Test
48 | public void testUseCatalog() {
49 | UseCatalogOperation operation = new UseCatalogOperation(context, "simple-catalog");
50 | assertEquals(OperationUtil.OK, operation.execute());
51 |
52 | assertEquals("simple-catalog", context.getExecutionContext().getTableEnvironment().getCurrentCatalog());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/operation/UseDatabaseOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.operation;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 | import com.ververica.flink.table.gateway.utils.EnvironmentFileUtil;
23 |
24 | import org.junit.Test;
25 |
26 | import java.util.HashMap;
27 | import java.util.Map;
28 |
29 | import static org.junit.Assert.assertEquals;
30 |
31 | /**
32 | * Tests for {@link UseDatabaseOperation}.
33 | */
34 | public class UseDatabaseOperationTest extends OperationTestBase {
35 |
36 | private static final String DEFAULTS_ENVIRONMENT_FILE = "test-sql-gateway-defaults.yaml";
37 |
38 | @Override
39 | protected Environment getSessionEnvironment() throws Exception {
40 | final Map replaceVars = new HashMap<>();
41 | replaceVars.put("$VAR_PLANNER", "old");
42 | replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
43 | replaceVars.put("$VAR_UPDATE_MODE", "");
44 | return EnvironmentFileUtil.parseModified(DEFAULTS_ENVIRONMENT_FILE, replaceVars);
45 | }
46 |
47 | @Test
48 | public void testUseDatabase() {
49 | context.getExecutionContext().getTableEnvironment().useCatalog("catalog1");
50 |
51 | UseDatabaseOperation operation = new UseDatabaseOperation(context, "default");
52 | assertEquals(OperationUtil.OK, operation.execute());
53 |
54 | assertEquals("default", context.getExecutionContext().getTableEnvironment().getCurrentDatabase());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/sink/dummy/DummyTableSinkFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package com.ververica.flink.table.gateway.sink.dummy;
21 |
22 | import com.ververica.flink.table.gateway.sink.TestTableSinkFactoryBase;
23 |
24 | /**
25 | * Dummy table sink factory.
26 | */
27 | public class DummyTableSinkFactory extends TestTableSinkFactoryBase {
28 |
29 | public static final String CONNECTOR_TYPE_VALUE = "dummy-sink";
30 | public static final String TEST_PROPERTY = "test-property";
31 |
32 | public DummyTableSinkFactory() {
33 | super(CONNECTOR_TYPE_VALUE, TEST_PROPERTY);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/source/dummy/DummyTableSourceFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package com.ververica.flink.table.gateway.source.dummy;
21 |
22 | import com.ververica.flink.table.gateway.source.TestTableSourceFactoryBase;
23 |
24 | /**
25 | * Dummy table source factory.
26 | */
27 | public class DummyTableSourceFactory extends TestTableSourceFactoryBase {
28 |
29 | public static final String CONNECTOR_TYPE_VALUE = "dummy-source";
30 | public static final String TEST_PROPERTY = "test-property";
31 |
32 | public DummyTableSourceFactory() {
33 | super(CONNECTOR_TYPE_VALUE, TEST_PROPERTY);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/source/random/RandomSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.source.random;
20 |
21 | import org.apache.flink.api.common.typeinfo.TypeInformation;
22 | import org.apache.flink.streaming.api.datastream.DataStream;
23 | import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
24 | import org.apache.flink.table.api.TableSchema;
25 | import org.apache.flink.table.sources.StreamTableSource;
26 | import org.apache.flink.table.types.DataType;
27 | import org.apache.flink.types.Row;
28 |
29 | import static org.apache.flink.table.types.utils.TypeConversions.fromDataTypeToLegacyInfo;
30 |
31 | /**
32 | * A user defined source which generates random data for testing purpose.
33 | */
34 | public class RandomSource implements StreamTableSource {
35 |
36 | private final TableSchema schema;
37 | private final long limit;
38 |
39 | private final RandomSourceFunction sourceFunction;
40 |
41 | public RandomSource(TableSchema schema, long limit) {
42 | this.schema = schema;
43 | this.limit = limit;
44 |
45 | this.sourceFunction = new RandomSourceFunction(schema, limit);
46 | }
47 |
48 | @Override
49 | public boolean isBounded() {
50 | return limit > 0;
51 | }
52 |
53 | @SuppressWarnings("unchecked")
54 | @Override
55 | public DataStream getDataStream(StreamExecutionEnvironment streamExecutionEnvironment) {
56 | TypeInformation typeInfo = (TypeInformation) fromDataTypeToLegacyInfo(getProducedDataType());
57 | return streamExecutionEnvironment.addSource(sourceFunction, typeInfo);
58 | }
59 |
60 | @Override
61 | public DataType getProducedDataType() {
62 | return schema.toRowDataType();
63 | }
64 |
65 | @Override
66 | public TableSchema getTableSchema() {
67 | return schema;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/source/random/RandomSourceFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.source.random;
20 |
21 | import org.apache.flink.table.api.TableSchema;
22 | import org.apache.flink.table.descriptors.ConnectorDescriptorValidator;
23 | import org.apache.flink.table.descriptors.DescriptorProperties;
24 | import org.apache.flink.table.descriptors.Schema;
25 | import org.apache.flink.table.factories.TableSourceFactory;
26 | import org.apache.flink.table.sources.TableSource;
27 | import org.apache.flink.types.Row;
28 |
29 | import java.util.Arrays;
30 | import java.util.Collections;
31 | import java.util.List;
32 | import java.util.Map;
33 | import java.util.Optional;
34 |
35 | /**
36 | * {@link TableSourceFactory} for creating {@link RandomSource}.
37 | */
38 | public class RandomSourceFactory implements TableSourceFactory {
39 |
40 | @Override
41 | public Map requiredContext() {
42 | return Collections.singletonMap(
43 | ConnectorDescriptorValidator.CONNECTOR_TYPE, RandomSourceValidator.CONNECTOR_TYPE_VALUE);
44 | }
45 |
46 | @Override
47 | public List supportedProperties() {
48 | return Arrays.asList(
49 | RandomSourceValidator.RANDOM_LIMIT,
50 | Schema.SCHEMA + ".#." + DescriptorProperties.DATA_TYPE,
51 | Schema.SCHEMA + ".#." + DescriptorProperties.NAME
52 | );
53 | }
54 |
55 | @Override
56 | public TableSource createTableSource(Map propertyMap) {
57 | DescriptorProperties properties = new DescriptorProperties();
58 | properties.putProperties(propertyMap);
59 |
60 | TableSchema schema = properties.getTableSchema(Schema.SCHEMA);
61 | Optional limit = properties.getOptionalInt(RandomSourceValidator.RANDOM_LIMIT);
62 | return new RandomSource(schema, limit.orElse(RandomSourceValidator.RANDOM_LIMIT_DEFAULT_VALUE));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/source/random/RandomSourceValidator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.source.random;
20 |
21 | import org.apache.flink.table.descriptors.ConnectorDescriptorValidator;
22 | import org.apache.flink.table.descriptors.DescriptorProperties;
23 |
24 | /**
25 | * Validator for {@link RandomSource}.
26 | */
27 | public class RandomSourceValidator extends ConnectorDescriptorValidator {
28 |
29 | public static final String CONNECTOR_TYPE_VALUE = "random";
30 | public static final String RANDOM_LIMIT = "random.limit";
31 | // this default value indicates that the random source is an unbounded source
32 | public static final int RANDOM_LIMIT_DEFAULT_VALUE = 0;
33 |
34 | @Override
35 | public void validate(DescriptorProperties properties) {
36 | super.validate(properties);
37 | properties.validateValue(CONNECTOR_TYPE, CONNECTOR_TYPE_VALUE, false);
38 | properties.validateInt(RANDOM_LIMIT, true, 1);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/utils/EnvironmentFileUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.utils;
20 |
21 | import com.ververica.flink.table.gateway.config.Environment;
22 |
23 | import org.apache.flink.util.FileUtils;
24 |
25 | import java.io.File;
26 | import java.io.IOException;
27 | import java.net.URL;
28 | import java.util.Map;
29 | import java.util.Objects;
30 |
31 | /**
32 | * Utilities for reading an environment file.
33 | */
34 | public final class EnvironmentFileUtil {
35 |
36 | private EnvironmentFileUtil() {
37 | // private
38 | }
39 |
40 | public static Environment parseUnmodified(String fileName) throws IOException {
41 | final URL url = EnvironmentFileUtil.class.getClassLoader().getResource(fileName);
42 | Objects.requireNonNull(url);
43 | return Environment.parse(url);
44 | }
45 |
46 | public static Environment parseModified(String fileName, Map replaceVars) throws IOException {
47 | final URL url = EnvironmentFileUtil.class.getClassLoader().getResource(fileName);
48 | Objects.requireNonNull(url);
49 | String schema = FileUtils.readFileUtf8(new File(url.getFile()));
50 |
51 | for (Map.Entry replaceVar : replaceVars.entrySet()) {
52 | schema = schema.replace(replaceVar.getKey(), replaceVar.getValue());
53 | }
54 |
55 | return Environment.parse(schema);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/com/ververica/flink/table/gateway/utils/ResourceFileUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package com.ververica.flink.table.gateway.utils;
20 |
21 | import java.io.BufferedReader;
22 | import java.io.File;
23 | import java.io.FileReader;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Utilities for reading a resource file.
28 | */
29 | public class ResourceFileUtils {
30 |
31 | public static String readAll(String resourceName) {
32 | File file = new File(ResourceFileUtils.class.getClassLoader().getResource(resourceName).getFile());
33 | try {
34 | FileReader fileReader = new FileReader(file);
35 | BufferedReader bufferedReader = new BufferedReader(fileReader);
36 | StringBuilder builder = new StringBuilder();
37 |
38 | String line;
39 | while ((line = bufferedReader.readLine()) != null) {
40 | builder.append(line).append('\n');
41 | }
42 | return builder.toString();
43 | } catch (IOException e) {
44 | throw new RuntimeException(e);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/resources/META-INF/services/org.apache.flink.table.factories.TableFactory:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | com.ververica.flink.table.gateway.sink.dummy.DummyTableSinkFactory
17 | com.ververica.flink.table.gateway.utils.SimpleCatalogFactory
18 | com.ververica.flink.table.gateway.config.DependencyTest$TestCatalogFactory
19 | com.ververica.flink.table.gateway.config.DependencyTest$TestHiveCatalogFactory
20 | com.ververica.flink.table.gateway.config.DependencyTest$TestModuleFactory
21 | com.ververica.flink.table.gateway.config.ExecutionContextTest$TestClassLoaderCatalogFactory
22 |
--------------------------------------------------------------------------------
/src/test/resources/plan/explain-operation-test.test-explain.expected:
--------------------------------------------------------------------------------
1 | == Abstract Syntax Tree ==
2 | LogicalProject(IntegerField1=[$0], StringField1=[$1])
3 | LogicalTableScan(table=[[default_catalog, default_database, TableNumber1]])
4 |
5 | == Optimized Logical Plan ==
6 | BatchTableSourceScan(table=[[default_catalog, default_database, TableNumber1]], fields=[IntegerField1, StringField1], source=[CsvTableSource(read fields: IntegerField1, StringField1)])
7 |
8 | == Physical Execution Plan ==
9 | : Data Source
10 | content : collect elements with CollectionInputFormat
11 | Partitioning : RANDOM_PARTITIONED
12 |
13 | : Data Sink
14 | content : org.apache.flink.api.java.io.DiscardingOutputFormat
15 | ship_strategy : Forward
16 | exchange_mode : PIPELINED
17 | Partitioning : RANDOM_PARTITIONED
18 |
19 |
--------------------------------------------------------------------------------
/src/test/resources/plan/operation-with-user-jar-test.test-explain.expected:
--------------------------------------------------------------------------------
1 | == Abstract Syntax Tree ==
2 | LogicalProject(a=[$0], b=[$1])
3 | +- LogicalTableScan(table=[[default_catalog, default_database, R, source: [RandomSource(a, b)]]])
4 |
5 | == Optimized Logical Plan ==
6 | LegacyTableSourceScan(table=[[default_catalog, default_database, R, source: [RandomSource(a, b)]]], fields=[a, b])
7 |
8 | == Physical Execution Plan ==
9 | : Data Source
10 | content : Source: Custom Source
11 |
12 | : Operator
13 | content : SourceConversion(table=[default_catalog.default_database.R, source: [RandomSource(a, b)]], fields=[a, b])
14 | ship_strategy : FORWARD
15 |
16 |
--------------------------------------------------------------------------------
/src/test/resources/service-file/test-factory-services-file:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | #==============================================================================
17 | # Test file for org.apache.flink.table.client.gateway.local.DependencyTest.
18 | #==============================================================================
19 |
20 | com.ververica.flink.table.gateway.config.DependencyTest$TestTableSourceFactory
21 | com.ververica.flink.table.gateway.config.DependencyTest$TestTableSinkFactory
22 |
--------------------------------------------------------------------------------
/src/test/resources/service-file/test-random-source-file:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | #==============================================================================
17 | # Test file for generating a random source jar.
18 | #==============================================================================
19 |
20 | com.ververica.flink.table.gateway.source.random.RandomSourceFactory
21 |
--------------------------------------------------------------------------------
/src/test/resources/test-data.csv:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | ################################################################################
18 | 42,Hello World
19 | 22,Hello World
20 | 32,Hello World
21 | 32,Hello World
22 | 42,Hello World
23 | 52,Hello World!!!!
24 |
--------------------------------------------------------------------------------
/src/test/resources/test-sql-gateway-configuration.yaml:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | ################################################################################
18 |
19 | #==============================================================================
20 | # TEST ENVIRONMENT FILE
21 | # This test file is to check whether the configuration can be successfully set.
22 | #==============================================================================
23 |
24 | execution:
25 | planner: blink
26 | type: batch
27 |
28 | configuration:
29 | table.exec.sort.default-limit: 100
30 | table.exec.spill-compression.enabled: true
31 | table.exec.spill-compression.block-size: 128kb
32 | table.optimizer.join-reorder-enabled: true
33 |
--------------------------------------------------------------------------------
/src/test/resources/test-sql-gateway-factory.yaml:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | ################################################################################
18 |
19 | #==============================================================================
20 | # TEST ENVIRONMENT FILE
21 | # Intended for org.apache.flink.table.client.gateway.local.DependencyTest.
22 | #==============================================================================
23 |
24 | # this file has variables that can be filled with content by replacing $VAR_XXX
25 |
26 | tables:
27 | - name: TableNumber1
28 | type: source-sink-table
29 | update-mode: append
30 | schema:
31 | - name: IntegerField1
32 | type: INT
33 | - name: StringField1
34 | type: VARCHAR
35 | - name: rowtimeField
36 | type: TIMESTAMP
37 | rowtime:
38 | timestamps:
39 | type: from-field
40 | from: rowtimeField
41 | watermarks:
42 | type: from-source
43 | connector:
44 | type: "$VAR_CONNECTOR_TYPE"
45 | $VAR_CONNECTOR_PROPERTY: "$VAR_CONNECTOR_PROPERTY_VALUE"
46 |
47 | execution:
48 | type: streaming
49 | parallelism: 1
50 |
51 | configuration:
52 | table.optimizer.join-reorder-enabled: true
53 |
54 | deployment:
55 | response-timeout: 5000
56 |
57 | catalogs:
58 | - name: catalog2
59 | type: DependencyTest
60 |
--------------------------------------------------------------------------------
/src/test/resources/test-sql-gateway-modules.yaml:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | ################################################################################
18 |
19 | #==============================================================================
20 | # TEST ENVIRONMENT FILE
21 | # General purpose default environment file.
22 | #==============================================================================
23 |
24 | # this file has variables that can be filled with content by replacing $VAR_XXX
25 |
26 | execution:
27 | planner: "$VAR_PLANNER"
28 | type: "$VAR_EXECUTION_TYPE"
29 | parallelism: 1
30 | max-parallelism: 16
31 |
32 | deployment:
33 | response-timeout: 5000
34 |
35 | modules:
36 | - name: core
37 | type: core
38 | - name: mymodule
39 | type: ModuleDependencyTest
40 | test: test
41 | - name: myhive
42 | type: hive
43 | - name: myhive2
44 | type: hive
45 | hive-version: 2.3.4
46 |
47 |
--------------------------------------------------------------------------------
/tools/maven/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------