示例#1
0
        //internal ResultSetResponse InternalTableTypesRequest()
        //{
        //    ResultSetResponse response = null;

        //    Task<ResultSetResponse> tResp = _client.TableTypesRequestAsync(this.ConnectionId, this.Options);

        //    tResp.Wait();

        //    response = tResp.Result;

        //    return response;
        //}

        internal async Task <GarudaExecuteResponse> InternalExecuteRequestAsync(PrepareResponse prepared, string sql,
                                                                                PhoenixParameterCollection parameterValues)
        {
            CreateStatementResponse tStmt   = null;
            ExecuteResponse         tResp   = null;
            GarudaExecuteResponse   ourResp = new GarudaExecuteResponse();

            try
            {
                if (null == prepared)
                {
                    try
                    {
                        // Not prepared....
                        tStmt = await _client.CreateStatementRequestAsync(this.ConnectionId, this.Options);

                        ourResp.StatementId = tStmt.StatementId;

                        tResp = await _client.PrepareAndExecuteRequestAsync(this.ConnectionId, sql, ourResp.StatementId, long.MaxValue, int.MaxValue, this.Options);
                    }
                    catch (Exception)
                    {
                        if (null != tStmt)
                        {
                            InternalCloseStatementAsync(tStmt.StatementId);
                        }

                        throw;
                    }
                }
                else
                {
                    // Prepared and possibly with parameters.
                    pbc.RepeatedField <TypedValue> pbParamValues = parameterValues.AsRepeatedFieldTypedValue();

                    tResp = await _client.ExecuteRequestAsync(prepared.Statement, pbParamValues, uint.MaxValue,
                                                              parameterValues.Count > 0, this.Options);
                }

                ourResp.Response = tResp;
            }
            catch (Exception ex)
            {
                if (OnInternalException(ex))
                {
                    throw;
                }
            }

            return(ourResp);
        }
示例#2
0
        public void CommitRollbackTest()
        {
            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 1
                pbc::MapField <string, string> info = new pbc::MapField <string, string>();
                openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
                // Syncing connection 1
                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, int.MaxValue, options).Result;
                StatementHandle statementHandle = prepareResponse.Statement;
                for (int i = 0; i < 10; 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, int.MaxValue, true, options).Result;
                }

                // Rollback
                client.RollbackRequestAsync(connId, options).Wait();

                // Commit statement 2
                client.CommitRequestAsync(connId, 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            count3        = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
                Assert.AreEqual(0, count3);

                // 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;
                }
            }
        }
示例#3
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;
                }
            }
        }