PhoenixSharp.PhoenixClient.PrepareAndExecuteRequestAsync C# (CSharp) Method

PrepareAndExecuteRequestAsync() public method

This request is used as a short-hand for create a Statement and fetching the first batch of results in a single call without any parameter substitution.
public PrepareAndExecuteRequestAsync ( string connectionId, string sql, uint statementId, long maxRowsTotal, int firstFrameMaxSize, RequestOptions options ) : Task
connectionId string
sql string
statementId uint
maxRowsTotal long
firstFrameMaxSize int
options RequestOptions
return Task
        public async Task<ExecuteResponse> PrepareAndExecuteRequestAsync(string connectionId, string sql, uint statementId, long maxRowsTotal, int firstFrameMaxSize, RequestOptions options)
        {
            PrepareAndExecuteRequest req = new PrepareAndExecuteRequest
            {
                Sql = sql,
                ConnectionId = connectionId,
                StatementId = statementId,
                MaxRowsTotal = maxRowsTotal,
                FirstFrameMaxSize = firstFrameMaxSize
            };

            WireMessage msg = new WireMessage
            {
                Name = Constants.WireMessagePrefix + "PrepareAndExecuteRequest",
                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(
                            "PrepareAndExecuteRequestAsync 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());
                    ExecuteResponse res = ExecuteResponse.Parser.ParseFrom(output.WrappedMessage);
                    return res;
                }
            }
        }

Usage Example

        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;
                }
            }
        }
All Usage Examples Of PhoenixSharp.PhoenixClient::PrepareAndExecuteRequestAsync