public void TestRetry()
        {
            var client = new PhoenixClient(_credentials);

            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            options.AlternativeEndpoint = "hbasephoenix0/";

            var attempts = 0;

            do
            {
                try
                {
                    attempts++;
                    string connId    = GenerateRandomConnId();
                    string tableName = "Persons" + connId;
                    OpenConnectionResponse         openConnResponse        = null;
                    CreateStatementResponse        createStatementResponse = null;
                    pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                    openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                    // Syncing connection
                    ConnectionProperties connProperties = new ConnectionProperties
                    {
                        HasAutoCommit        = true,
                        AutoCommit           = true,
                        HasReadOnly          = true,
                        ReadOnly             = false,
                        TransactionIsolation = 0,
                        Catalog = "",
                        Schema  = "",
                        IsDirty = true
                    };
                    client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                    createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                    break;
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException().Message.Contains("NoSuchConnectionException"))
                    {
                        continue;
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            } while (attempts < 10);

            if (attempts == 10)
            {
                Assert.Fail();
            }
        }
Esempio n. 2
0
        public void TableOperationTest()
        {
            var            client  = new PhoenixClient(_credentials);
            string         connId  = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, PQS requests will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            OpenConnectionResponse openConnResponse = null;

            try
            {
                // Opening connection
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                // List system tables
                pbc.RepeatedField <string> list = new pbc.RepeatedField <string>();
                list.Add("SYSTEM TABLE");
                ResultSetResponse tablesResponse = client.TablesRequestAsync("", "", "", list, true, connId, options).Result;
                Assert.AreEqual(4, tablesResponse.FirstFrame.Rows.Count);

                // List all table types
                ResultSetResponse tableTypeResponse = client.TableTypesRequestAsync(connId, options).Result;
                Assert.AreEqual(6, tableTypeResponse.FirstFrame.Rows.Count);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 3
0
        public void TableOperationTest()
        {
            var            client  = new PhoenixClient(null);
            string         connId  = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetVNetDefaultOptions();

            // In VNET mode, PQS requests will be http://<PQS workernode ip>:8765
            options.AlternativeHost = "10.17.0.13";
            OpenConnectionResponse openConnResponse = null;

            try
            {
                // Opening connection
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                // List system tables
                pbc.RepeatedField <string> list = new pbc.RepeatedField <string>();
                list.Add("SYSTEM TABLE");
                ResultSetResponse tablesResponse = client.TablesRequestAsync("", "", "", list, true, connId, options).Result;
                Assert.AreEqual(4, tablesResponse.FirstFrame.Rows.Count);

                // List all table types
                ResultSetResponse tableTypeResponse = client.TableTypesRequestAsync(connId, options).Result;
                Assert.AreEqual(6, tableTypeResponse.FirstFrame.Rows.Count);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 4
0
        public void TableOperationTest()
        {
            var client = new PhoenixClient(null);
            string connId = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetVNetDefaultOptions();
            // In VNET mode, PQS requests will be http://<PQS workernode ip>:8765
            options.AlternativeHost = "10.17.0.13";
            OpenConnectionResponse openConnResponse = null;
            try
            {
                // Opening connection
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                // List system tables
                pbc.RepeatedField<string> list = new pbc.RepeatedField<string>();
                list.Add("SYSTEM TABLE");
                ResultSetResponse tablesResponse = client.TablesRequestAsync("", "", "", list, true, connId, options).Result;
                Assert.AreEqual(4, tablesResponse.FirstFrame.Rows.Count);

                // List all table types
                ResultSetResponse tableTypeResponse = client.TableTypesRequestAsync(connId, options).Result;
                Assert.AreEqual(6, tableTypeResponse.FirstFrame.Rows.Count);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 5
0
        private async Task PrivateOpenAsync()
        {
            if (null == _client)
            {
                // Spin up Microsoft.Phoenix.Client
                _client = new PhoenixClient(this.Credentials);
            }

            if (this.State == ConnectionState.Closed ||
                this.State == ConnectionState.Broken)
            {
                // Update state....
                this.State = ConnectionState.Connecting;

                pbc::MapField <string, string> info = new pbc::MapField <string, string>();

                // Initiate connection
                var tOpen = await _client.OpenConnectionRequestAsync(this.ConnectionId,
                                                                     info,
                                                                     this.Options);

                _openConnection = tOpen;

                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                await _client.ConnectionSyncRequestAsync(this.ConnectionId, connProperties, this.Options);

                // Connected.
                this.State = ConnectionState.Open;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// This request is used to open a new Connection in the Phoenix query server.
        /// </summary>
        public async Task <OpenConnectionResponse> OpenConnectionRequestAsync(string connectionId, pbc::MapField <string, string> info, RequestOptions options)
        {
            OpenConnectionRequest req = new OpenConnectionRequest
            {
                ConnectionId = connectionId,
                Info         = info
            };

            WireMessage msg = new WireMessage
            {
                Name           = Constants.WireMessagePrefix + "OpenConnectionRequest",
                WrappedMessage = req.ToByteString()
            };

            using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options))
            {
                if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK)
                {
                    WireMessage   output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    ErrorResponse res    = ErrorResponse.Parser.ParseFrom(output.WrappedMessage);
                    throw new WebException(
                              string.Format(
                                  "OpenConnectionRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}",
                                  connectionId,
                                  webResponse.WebResponse.StatusCode,
                                  res.ToString()));
                }
                else
                {
                    WireMessage            output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream());
                    OpenConnectionResponse res    = OpenConnectionResponse.Parser.ParseFrom(output.WrappedMessage);
                    return(res);
                }
            }
        }
Esempio n. 7
0
        public void SimpleTest()
        {
            var            client  = new PhoenixClient(_credentials);
            string         connId  = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;
            OpenConnectionResponse  openConnResponse        = null;
            CreateStatementResponse createStatementResponse = null;

            try
            {
                // Opening connection
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();


                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Running query 2
                string sql2 = "UPSERT INTO " + tableName + " VALUES ('d1','x1')";
                client.PrepareAndExecuteRequestAsync(connId, sql2, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Running query 3
                string          sql3          = "select count(*) from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long            count         = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(1, count);

                // Running query 4
                string sql4 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 8
0
        public void RowInsertWithArbitraryTimestamp()
        {
            // https://phoenix.apache.org/faq.html#Can_phoenix_work_on_tables_with_arbitrary_timestamp_as_flexible_as_HBase_API
            // The table creation time must not be later than the row insert timestamp
            // Otherwise will get table NOT FOUND exception
            // Row insert time must not be later than row query time
            // Otherwise the row will not appear in the resultset
            var            client  = new PhoenixClient(_credentials);
            string         connId  = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;
            OpenConnectionResponse  openConnResponse        = null;
            CreateStatementResponse createStatementResponse = null;

            try
            {
                // Opening connection
                // Set table creation time to 0
                long ts = 0;
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                info.Add("CurrentSCN", ts.ToString());
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }

            // insert row with specified timestamp
            try
            {
                // Opening connection
                long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                info.Add("CurrentSCN", ts.ToString());
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 2
                string sql2 = "UPSERT INTO " + tableName + " VALUES ('d1','x1')";
                client.PrepareAndExecuteRequestAsync(connId, sql2, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }

            // query row with specified timestamp
            try
            {
                // Opening connection
                long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                info.Add("CurrentSCN", ts.ToString());
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;

                // Running query 3
                string          sql3          = "select count(*) from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long            count         = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(1, count);

                // Running query 4
                string sql4 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 9
0
        public void ManyRowBatchInsertTest()
        {
            var            client  = new PhoenixClient(_credentials);
            string         connId  = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;

            OpenConnectionResponse  openConnResponse        = null;
            CreateStatementResponse createStatementResponse = null;

            try
            {
                // Opening connection
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                // Creating statement
                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;

                // Running query 1
                string          sql1          = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                ExecuteResponse execResponse1 = client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;

                // Running query 2
                // Batching two sqls in a single HTTP request
                pbc::RepeatedField <string> list = new pbc.RepeatedField <string>();
                list.Add("UPSERT INTO " + tableName + " VALUES('d1','x1')");
                list.Add("UPSERT INTO " + tableName + " VALUES('d2','x2')");
                ExecuteBatchResponse execResponse2 = client.PrepareAndExecuteBatchRequestAsync(connId, createStatementResponse.StatementId, list, options).Result;

                // Running query 3
                string          sql3          = "select count(*) from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long            count3        = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(2, count3);

                // Running query 4
                // Batching two sqls in a single HTTP request
                // Creating statement 2
                string          sql4                     = "UPSERT INTO " + tableName + " VALUES (?,?)";
                PrepareResponse prepareResponse          = client.PrepareRequestAsync(connId, sql4, int.MaxValue, options).Result;
                StatementHandle statementHandle          = prepareResponse.Statement;
                pbc::RepeatedField <UpdateBatch> updates = new pbc.RepeatedField <UpdateBatch>();
                for (int i = 3; i < 10; i++)
                {
                    pbc::RepeatedField <TypedValue> parameterValues = new pbc.RepeatedField <TypedValue>();
                    TypedValue v1 = new TypedValue
                    {
                        StringValue = "d" + i,
                        Type        = Rep.String
                    };
                    TypedValue v2 = new TypedValue
                    {
                        StringValue = "x" + i,
                        Type        = Rep.String
                    };
                    parameterValues.Add(v1);
                    parameterValues.Add(v2);
                    UpdateBatch batch = new UpdateBatch
                    {
                        ParameterValues = parameterValues
                    };
                    updates.Add(batch);
                }
                ExecuteBatchResponse execResponse4 = client.ExecuteBatchRequestAsync(connId, statementHandle.Id, updates, options).Result;

                // Running query 5
                string          sql5          = "select count(*) from " + tableName;
                ExecuteResponse execResponse5 = client.PrepareAndExecuteRequestAsync(connId, sql5, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long            count5        = execResponse5.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(9, count5);

                // Running query 5
                string sql6 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql6, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 10
0
        public void QueryManyRowTest()
        {
            var            client  = new PhoenixClient(_credentials);
            string         connId  = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;

            OpenConnectionResponse  openConnResponse        = null;
            CreateStatementResponse createStatementResponse = null;

            try
            {
                // Opening connection
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = false,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Commit statement 1
                client.CommitRequestAsync(connId, options).Wait();

                // Creating statement 2
                string          sql2            = "UPSERT INTO " + tableName + " VALUES (?,?)";
                PrepareResponse prepareResponse = client.PrepareRequestAsync(connId, sql2, long.MaxValue, options).Result;
                StatementHandle statementHandle = prepareResponse.Statement;
                // Insert 300 rows
                for (int i = 0; i < 300; i++)
                {
                    pbc::RepeatedField <TypedValue> list = new pbc.RepeatedField <TypedValue>();
                    TypedValue v1 = new TypedValue
                    {
                        StringValue = "d" + i,
                        Type        = Rep.String
                    };
                    TypedValue v2 = new TypedValue
                    {
                        StringValue = "x" + i,
                        Type        = Rep.String
                    };
                    list.Add(v1);
                    list.Add(v2);
                    ExecuteResponse executeResponse = client.ExecuteRequestAsync(statementHandle, list, long.MaxValue, true, options).Result;
                }

                // Commit statement 2
                client.CommitRequestAsync(connId, options).Wait();

                // Running query 3
                string                   sql3          = "select * from " + tableName;
                ExecuteResponse          execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                pbc::RepeatedField <Row> rows          = execResponse3.Results[0].FirstFrame.Rows;
                for (int i = 0; i < rows.Count; i++)
                {
                    Row row = rows[i];
                    Debug.WriteLine(row.Value[0].ScalarValue.StringValue + " " + row.Value[1].ScalarValue.StringValue);
                }
                // 100 is hard coded in server side as default firstframe size
                // In order to get remaining rows, FetchRequestAsync is used
                Assert.AreEqual(100, rows.Count);

                // Fetch remaining rows, offset is not used, simply set to 0
                // if FetchResponse.Frame.Done = true, that means all the rows fetched
                FetchResponse fetchResponse = client.FetchRequestAsync(connId, createStatementResponse.StatementId, 0, int.MaxValue, options).Result;
                Assert.AreEqual(200, fetchResponse.Frame.Rows.Count);
                Assert.AreEqual(true, fetchResponse.Frame.Done);


                // Running query 4
                string sql4 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Commit statement 4
                client.CommitRequestAsync(connId, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
Esempio n. 11
0
        public static async void ExecuteProcedure(DataContract dataContract)
        {
            string         connId      = Guid.NewGuid().ToString();
            RequestOptions options     = RequestOptions.GetGatewayDefaultOptions();
            var            credentials = new ClusterCredentials(new Uri("jdbc:phoenix:10.16.0.206:/hbase-unsecure"), null, null);
            var            client      = new PhoenixClient(credentials);

            // In gateway mode, PQS requests will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            OpenConnectionResponse openConnResponse = null;
            StatementHandle        statementHandle  = null;

            try
            {
                //var info = new pbc::MapField<string, string>();
                // Opening connection
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = await client.OpenConnectionRequestAsync(connId, info, options);

                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit        = true,
                    AutoCommit           = true,
                    HasReadOnly          = true,
                    ReadOnly             = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema  = "",
                    IsDirty = true
                };
                await client.ConnectionSyncRequestAsync(connId, connProperties, options);

                var createStatementResponse = await client.CreateStatementRequestAsync(connId, options);

                string          sql             = "SELECT * FROM Customers";
                ExecuteResponse executeResponse = await client.PrepareAndExecuteRequestAsync(connId, sql, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options);

                pbc::RepeatedField <Row> rows = executeResponse.Results[0].FirstFrame.Rows;
                // Loop through all of the returned rows and display the first two columns
                for (int i = 0; i < rows.Count; i++)
                {
                    Row row = rows[i];
                    Console.WriteLine(row.Value[0].ScalarValue.StringValue + " " + row.Value[1].ScalarValue.StringValue);
                }

                // 100 is hard-coded on the server side as the default firstframe size
                // FetchRequestAsync is called to get any remaining rows
                Console.WriteLine("");
                Console.WriteLine($"Number of rows: {rows.Count}");

                // Fetch remaining rows, offset is not used, simply set to 0
                // When FetchResponse.Frame.Done is true, all rows were fetched
                FetchResponse fetchResponse = await client.FetchRequestAsync(connId, createStatementResponse.StatementId, 0, int.MaxValue, options);

                Console.WriteLine($"Frame row count: {fetchResponse.Frame.Rows.Count}");
                Console.WriteLine($"Fetch response is done: {fetchResponse.Frame.Done}");
                Console.WriteLine("");

                // Running query 2
                string          sql2          = "select count(*) from Customers";
                ExecuteResponse countResponse = await client.PrepareAndExecuteRequestAsync(connId, sql2, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options);

                long count = countResponse.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;

                Console.WriteLine($"Total customer records: {count}");
                Console.WriteLine("");

                // Running query 3
                string          sql3            = "select StateProvince, count(*) as Number from Customers group by StateProvince order by Number desc";
                ExecuteResponse groupByResponse = await client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options);

                pbc::RepeatedField <Row> stateRows = groupByResponse.Results[0].FirstFrame.Rows;
                for (int i = 0; i < stateRows.Count; i++)
                {
                    Row row = stateRows[i];
                    Console.WriteLine(row.Value[0].ScalarValue.StringValue + ": " + row.Value[1].ScalarValue.NumberValue);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (statementHandle != null)
                {
                    await client.CloseStatementRequestAsync(connId, statementHandle.Id, options);

                    statementHandle = null;
                }
                if (openConnResponse != null)
                {
                    await client.CloseConnectionRequestAsync(connId, options);

                    openConnResponse = null;
                }
            }
        }
        public void TableOperationTest()
        {
            var client = new PhoenixClient(_credentials);
            string connId = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, PQS requests will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            OpenConnectionResponse openConnResponse = null;
            try
            {
                // Opening connection
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                // List system tables
                pbc.RepeatedField<string> list = new pbc.RepeatedField<string>();
                list.Add("SYSTEM TABLE");
                ResultSetResponse tablesResponse = client.TablesRequestAsync("", "", "", list, true, connId, options).Result;
                Assert.AreEqual(4, tablesResponse.FirstFrame.Rows.Count);

                // List all table types
                ResultSetResponse tableTypeResponse = client.TableTypesRequestAsync(connId, options).Result;
                Assert.AreEqual(6, tableTypeResponse.FirstFrame.Rows.Count);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
        public void SimpleTest()
        {
            var client = new PhoenixClient(_credentials);
            string connId = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;
            OpenConnectionResponse openConnResponse = null;
            CreateStatementResponse createStatementResponse = null;
            try
            {
                // Opening connection
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Running query 2
                string sql2 = "UPSERT INTO " + tableName + " VALUES ('d1','x1')";
                client.PrepareAndExecuteRequestAsync(connId, sql2, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Running query 3
                string sql3 = "select count(*) from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long count = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(1, count);

                // Running query 4
                string sql4 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
        public void RowInsertWithArbitraryTimestamp()
        {
            // https://phoenix.apache.org/faq.html#Can_phoenix_work_on_tables_with_arbitrary_timestamp_as_flexible_as_HBase_API
            // The table creation time must not be later than the row insert timestamp
            // Otherwise will get table NOT FOUND exception
            // Row insert time must not be later than row query time
            // Otherwise the row will not appear in the resultset
            var client = new PhoenixClient(_credentials);
            string connId = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;
            OpenConnectionResponse openConnResponse = null;
            CreateStatementResponse createStatementResponse = null;
            try
            {
                // Opening connection
                // Set table creation time to 0
                long ts = 0;
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                info.Add("CurrentSCN", ts.ToString());
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }

            // insert row with specified timestamp
            try
            {
                // Opening connection
                long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                info.Add("CurrentSCN", ts.ToString());
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 2
                string sql2 = "UPSERT INTO " + tableName + " VALUES ('d1','x1')";
                client.PrepareAndExecuteRequestAsync(connId, sql2, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }

            // query row with specified timestamp
            try
            {
                // Opening connection
                long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds;
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                info.Add("CurrentSCN", ts.ToString());
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;

                // Running query 3
                string sql3 = "select count(*) from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long count = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(1, count);

                // Running query 4
                string sql4 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
        public void QueryManyRowTest()
        {
            var client = new PhoenixClient(_credentials);
            string connId = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;

            OpenConnectionResponse openConnResponse = null;
            CreateStatementResponse createStatementResponse = null;
            try
            {
                // Opening connection
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = false,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Commit statement 1
                client.CommitRequestAsync(connId, options).Wait();

                // Creating statement 2
                string sql2 = "UPSERT INTO " + tableName + " VALUES (?,?)";
                PrepareResponse prepareResponse = client.PrepareRequestAsync(connId, sql2, long.MaxValue, options).Result;
                StatementHandle statementHandle = prepareResponse.Statement;
                // Insert 300 rows
                for (int i = 0; i < 300; i++)
                {
                    pbc::RepeatedField<TypedValue> list = new pbc.RepeatedField<TypedValue>();
                    TypedValue v1 = new TypedValue
                    {
                        StringValue = "d" + i,
                        Type = Rep.String
                    };
                    TypedValue v2 = new TypedValue
                    {
                        StringValue = "x" + i,
                        Type = Rep.String
                    };
                    list.Add(v1);
                    list.Add(v2);
                    ExecuteResponse executeResponse = client.ExecuteRequestAsync(statementHandle, list, long.MaxValue, true, options).Result;
                }

                // Commit statement 2
                client.CommitRequestAsync(connId, options).Wait();

                // Running query 3
                string sql3 = "select * from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                pbc::RepeatedField<Row> rows = execResponse3.Results[0].FirstFrame.Rows;
                for (int i = 0; i < rows.Count; i++)
                {
                    Row row = rows[i];
                    Debug.WriteLine(row.Value[0].ScalarValue.StringValue + " " + row.Value[1].ScalarValue.StringValue);
                }
                // 100 is hard coded in server side as default firstframe size
                // In order to get remaining rows, FetchRequestAsync is used
                Assert.AreEqual(100, rows.Count);

                // Fetch remaining rows, offset is not used, simply set to 0
                // if FetchResponse.Frame.Done = true, that means all the rows fetched
                FetchResponse fetchResponse = client.FetchRequestAsync(connId, createStatementResponse.StatementId, 0, int.MaxValue, options).Result;
                Assert.AreEqual(200, fetchResponse.Frame.Rows.Count);
                Assert.AreEqual(true, fetchResponse.Frame.Done);

                // Running query 4
                string sql4 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();

                // Commit statement 4
                client.CommitRequestAsync(connId, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }
        public void ManyRowBatchInsertTest()
        {
            var client = new PhoenixClient(_credentials);
            string connId = GenerateRandomConnId();
            RequestOptions options = RequestOptions.GetGatewayDefaultOptions();

            // In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
            // Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
            options.AlternativeEndpoint = "hbasephoenix0/";
            string tableName = "Persons" + connId;

            OpenConnectionResponse openConnResponse = null;
            CreateStatementResponse createStatementResponse = null;
            try
            {
                // Opening connection
                pbc::MapField<string, string> info = new pbc::MapField<string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection
                ConnectionProperties connProperties = new ConnectionProperties
                {
                    HasAutoCommit = true,
                    AutoCommit = true,
                    HasReadOnly = true,
                    ReadOnly = false,
                    TransactionIsolation = 0,
                    Catalog = "",
                    Schema = "",
                    IsDirty = true
                };
                client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();

                // Creating statement
                createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;

                // Running query 1
                string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
                ExecuteResponse execResponse1 = client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;

                // Running query 2
                // Batching two sqls in a single HTTP request
                pbc::RepeatedField<string> list = new pbc.RepeatedField<string>();
                list.Add("UPSERT INTO " + tableName + " VALUES('d1','x1')");
                list.Add("UPSERT INTO " + tableName + " VALUES('d2','x2')");
                ExecuteBatchResponse execResponse2 = client.PrepareAndExecuteBatchRequestAsync(connId, createStatementResponse.StatementId, list, options).Result;

                // Running query 3
                string sql3 = "select count(*) from " + tableName;
                ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long count3 = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(2, count3);

                // Running query 4
                // Batching two sqls in a single HTTP request
                // Creating statement 2
                string sql4 = "UPSERT INTO " + tableName + " VALUES (?,?)";
                PrepareResponse prepareResponse = client.PrepareRequestAsync(connId, sql4, int.MaxValue, options).Result;
                StatementHandle statementHandle = prepareResponse.Statement;
                pbc::RepeatedField<UpdateBatch> updates = new pbc.RepeatedField<UpdateBatch>();
                for (int i = 3; i < 10; i++)
                {
                    pbc::RepeatedField<TypedValue> parameterValues = new pbc.RepeatedField<TypedValue>();
                    TypedValue v1 = new TypedValue
                    {
                        StringValue = "d" + i,
                        Type = Rep.String
                    };
                    TypedValue v2 = new TypedValue
                    {
                        StringValue = "x" + i,
                        Type = Rep.String
                    };
                    parameterValues.Add(v1);
                    parameterValues.Add(v2);
                    UpdateBatch batch = new UpdateBatch
                    {
                        ParameterValues = parameterValues
                    };
                    updates.Add(batch);
                }
                ExecuteBatchResponse execResponse4 = client.ExecuteBatchRequestAsync(connId, statementHandle.Id, updates, options).Result;

                // Running query 5
                string sql5 = "select count(*) from " + tableName;
                ExecuteResponse execResponse5 = client.PrepareAndExecuteRequestAsync(connId, sql5, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
                long count5 = execResponse5.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(9, count5);

                // Running query 5
                string sql6 = "DROP TABLE " + tableName;
                client.PrepareAndExecuteRequestAsync(connId, sql6, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (createStatementResponse != null)
                {
                    client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
                    createStatementResponse = null;
                }

                if (openConnResponse != null)
                {
                    client.CloseConnectionRequestAsync(connId, options).Wait();
                    openConnResponse = null;
                }
            }
        }