Пример #1
0
        public async Task TestGetInfo()
        {
            var response = await SqlGatewayApi.GetInfoAsync();

            Assert.NotNull(response);
            Assert.False(string.IsNullOrWhiteSpace(response.ProductName));
            Assert.False(string.IsNullOrWhiteSpace(response.Version));
        }
Пример #2
0
        public async ValueTask DisposeAsync()
        {
            if (string.IsNullOrWhiteSpace(SessionId))
            {
                return;
            }

            await SqlGatewayApi.CloseSessionAsync(SessionId);

            SessionId = null;
        }
Пример #3
0
        internal async Task GetInfoAsync()
        {
            var response = await SqlGatewayApi.GetInfoAsync();

            if (response is null || string.IsNullOrWhiteSpace(response.Version))
            {
                throw new FlinkSqlException("connect gateway api failed");
            }

            Version = response.Version;
        }
Пример #4
0
        internal Task <ResultFetchResponse> FetchResultAsync(string jobId, long token)
        {
            if (string.IsNullOrWhiteSpace(jobId))
            {
                throw new ArgumentNullException(nameof(jobId));
            }

            if (token < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(token), "token must be greater than or equal to zero.");
            }

            return(SqlGatewayApi.FetchResultAsync(SessionId, jobId, token));
        }
Пример #5
0
        internal Task <StatementExecuteResponse> ExecuteStatementAsync(string sqlStatement, long executionTimeoutMillis)
        {
            if (string.IsNullOrWhiteSpace(sqlStatement))
            {
                throw new ArgumentNullException(nameof(sqlStatement));
            }

            var requestParam = new StatementExecuteRequest
            {
                Statement        = sqlStatement,
                ExecutionTimeout = executionTimeoutMillis
            };

            return(SqlGatewayApi.ExecuteStatementAsync(SessionId, requestParam));
        }
Пример #6
0
        public async Task TestSessionOperation()
        {
            var response = await SqlGatewayApi.CreateSessionAsync(new SessionCreateRequest
            {
                Planner       = "blink",
                ExecutionType = "batch"
            });

            Assert.NotNull(response);
            Assert.False(string.IsNullOrWhiteSpace(response.SessionId));

            await SqlGatewayApi.HeartbeatSessionAsync(response.SessionId);

            var closeResponse = await SqlGatewayApi.CloseSessionAsync(response.SessionId);

            Assert.NotNull(closeResponse);
            Assert.True(string.Compare(closeResponse.Status, "CLOSED", true) == 0);
        }
Пример #7
0
        internal async Task ConnectAsync(CancellationToken cancellationToken)
        {
            await GetInfoAsync();

            cancellationToken.ThrowIfCancellationRequested();

            //currently the Ado.Net interfaces designed for database, not support on streaming
            var response = await SqlGatewayApi.CreateSessionAsync(new SessionCreateRequest
            {
                Planner       = ConnectionSettings.Planner,
                ExecutionType = "batch"
            });

            if (response is null || string.IsNullOrWhiteSpace(response.SessionId))
            {
                throw new FlinkSqlException("create session failed");
            }

            SessionId = response.SessionId;
        }
Пример #8
0
        public async Task TestExecuteStatement()
        {
            var response = await SqlGatewayApi.CreateSessionAsync(new SessionCreateRequest
            {
                Planner       = "blink",
                ExecutionType = "batch"
            });

            Assert.NotNull(response);
            Assert.False(string.IsNullOrWhiteSpace(response.SessionId));

            var executeResponse = await SqlGatewayApi.ExecuteStatementAsync(response.SessionId, new StatementExecuteRequest
            {
                Statement = "CREATE TABLE T(\n" +
                            "  a INT,\n" +
                            "  b VARCHAR(10)\n" +
                            ") WITH (\n" +
                            "  'connector.type' = 'filesystem',\n" +
                            "  'connector.path' = 'file:///tmp/T.csv',\n" +
                            "  'format.type' = 'csv',\n" +
                            "  'format.derive-schema' = 'true'\n" +
                            ")",
                ExecutionTimeout = long.MaxValue
            });

            Assert.NotNull(executeResponse);
            Assert.NotNull(executeResponse.StatementTypes);
            Assert.True(string.Compare(executeResponse.StatementTypes[0], "CREATE_TABLE", true) == 0);

            executeResponse = await SqlGatewayApi.ExecuteStatementAsync(response.SessionId, new StatementExecuteRequest
            {
                Statement        = "INSERT INTO T VALUES (1, 'Hi'), (2, 'Hello')",
                ExecutionTimeout = long.MaxValue
            });

            Assert.NotNull(executeResponse);
            Assert.NotNull(executeResponse.StatementTypes);
            Assert.True(string.Compare(executeResponse.StatementTypes[0], "INSERT_INTO", true) == 0);

            Assert.NotNull(executeResponse.Results);
            Assert.NotNull(executeResponse.Results[0].Data);
            var jobId = Convert.ToString(executeResponse.Results[0].Data[0][0]);

            Assert.False(string.IsNullOrWhiteSpace(jobId));

            executeResponse = await SqlGatewayApi.ExecuteStatementAsync(response.SessionId, new StatementExecuteRequest
            {
                Statement        = "SELECT * FROM T",
                ExecutionTimeout = 30 * 1000L
            });

            Assert.NotNull(executeResponse);
            Assert.NotNull(executeResponse.StatementTypes);
            Assert.True(string.Compare(executeResponse.StatementTypes[0], "SELECT", true) == 0);

            Assert.NotNull(executeResponse.Results);
            Assert.NotNull(executeResponse.Results[0].Data);
            jobId = Convert.ToString(executeResponse.Results[0].Data[0][0]);
            Assert.False(string.IsNullOrWhiteSpace(jobId));

            var closeResponse = await SqlGatewayApi.CloseSessionAsync(response.SessionId);

            Assert.NotNull(closeResponse);
            Assert.True(string.Compare(closeResponse.Status, "CLOSED", true) == 0);
        }
Пример #9
0
        public async Task TestFetchResult()
        {
            var response = await SqlGatewayApi.CreateSessionAsync(new SessionCreateRequest
            {
                Planner       = "blink",
                ExecutionType = "batch"
            });

            Assert.NotNull(response);
            Assert.False(string.IsNullOrWhiteSpace(response.SessionId));

            var executeResponse = await SqlGatewayApi.ExecuteStatementAsync(response.SessionId, new StatementExecuteRequest
            {
                Statement = "CREATE TABLE T(\n" +
                            "  a INT,\n" +
                            "  b VARCHAR(10)\n" +
                            ") WITH (\n" +
                            "  'connector.type' = 'filesystem',\n" +
                            "  'connector.path' = 'file:///tmp/T.csv',\n" +
                            "  'format.type' = 'csv',\n" +
                            "  'format.derive-schema' = 'true'\n" +
                            ")",
                ExecutionTimeout = long.MaxValue
            });

            Assert.NotNull(executeResponse);

            executeResponse = await SqlGatewayApi.ExecuteStatementAsync(response.SessionId, new StatementExecuteRequest
            {
                Statement        = "INSERT INTO T VALUES (1, 'Hi'), (2, 'Hello')",
                ExecutionTimeout = long.MaxValue
            });

            Assert.NotNull(executeResponse);

            executeResponse = await SqlGatewayApi.ExecuteStatementAsync(response.SessionId, new StatementExecuteRequest
            {
                Statement        = "SELECT * FROM T",
                ExecutionTimeout = 30 * 1000L
            });

            Assert.NotNull(executeResponse);
            Assert.NotNull(executeResponse.StatementTypes);
            Assert.True(string.Compare(executeResponse.StatementTypes[0], "SELECT", true) == 0);

            Assert.NotNull(executeResponse.Results);
            Assert.NotNull(executeResponse.Results[0].Data);
            var jobId = Convert.ToString(executeResponse.Results[0].Data[0][0]);

            Assert.False(string.IsNullOrWhiteSpace(jobId));

            var jobStatusResponse = await SqlGatewayApi.GetJobStatusAsync(response.SessionId, jobId);

            Assert.NotNull(jobStatusResponse);
            Assert.True(string.Compare(jobStatusResponse.Status, "RUNNING", true) == 0);

            #region Fetch Result
            long token         = 0;
            var  fetchResponse = await SqlGatewayApi.FetchResultAsync(response.SessionId, jobId, token);

            Assert.NotNull(fetchResponse);

            while (!string.IsNullOrWhiteSpace(fetchResponse.NextResultUri))
            {
                fetchResponse = await SqlGatewayApi.FetchResultAsync(response.SessionId, jobId, ++token);

                Assert.NotNull(fetchResponse);
                if (fetchResponse.Results != null)
                {
                    foreach (var rowData in fetchResponse.Results[0].Data)
                    {
                        Assert.True(Convert.ToInt32(Convert.ToString(rowData[0])) > 0);
                        Assert.False(string.IsNullOrWhiteSpace(Convert.ToString(rowData[1])));
                    }
                }
            }
            #endregion

            jobStatusResponse = await SqlGatewayApi.CancelJobAsync(response.SessionId, jobId);

            Assert.NotNull(jobStatusResponse);
            Assert.True(string.Compare(jobStatusResponse.Status, "CANCELED", true) == 0);

            var closeResponse = await SqlGatewayApi.CloseSessionAsync(response.SessionId);

            Assert.NotNull(closeResponse);
            Assert.True(string.Compare(closeResponse.Status, "CLOSED", true) == 0);
        }