Exemplo n.º 1
0
        /// <summary>
        /// This request is used to fetch the table types available in this database.
        /// </summary>
        public async Task <ResultSetResponse> TableTypesRequestAsync(string connectionId, RequestOptions options)
        {
            TableTypesRequest req = new TableTypesRequest
            {
                ConnectionId = connectionId
            };

            WireMessage msg = new WireMessage
            {
                Name           = Constants.WireMessagePrefix + "TableTypesRequest",
                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(
                                  "TableTypesRequestAsync 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());
                    ResultSetResponse res    = ResultSetResponse.Parser.ParseFrom(output.WrappedMessage);
                    return(res);
                }
            }
        }
Exemplo n.º 2
0
        private int GetNdxOfColumn(ResultSetResponse resp, string name)
        {
            for (int i = 0; i < resp.Signature.Columns.Count; i++)
            {
                if (name == resp.Signature.Columns[i].ColumnName)
                {
                    return(i);
                }
            }

            throw new KeyNotFoundException(name);
        }
Exemplo n.º 3
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;
                }
            }
        }
Exemplo n.º 4
0
        internal ResultSetResponse InternalTablesRequest(pbc.RepeatedField <string> list)
        {
            ResultSetResponse response = null;

            Task <ResultSetResponse> tResp = _client.TablesRequestAsync("", "", "", list, true, this.ConnectionId, this.Options);

            tResp.Wait();

            response = tResp.Result;

            return(response);
        }
Exemplo n.º 5
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;
                }
            }
        }
Exemplo n.º 6
0
        internal PhoenixDataReader(PhoenixConnection connection, ResultSetResponse response)
        {
            if (null == connection)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (null == response)
            {
                throw new ArgumentNullException(nameof(response));
            }

            _connection = connection;

            GarudaResultSet grs = new GarudaResultSet(response.Signature, response.FirstFrame, response.UpdateCount);

            _resultSets.Add(grs);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This request is used to fetch the tables available in this database filtered by the provided criteria.
        /// </summary>
        public async Task <ResultSetResponse> TablesRequestAsync(string catalog, string schemaPattern, string tableNamePattern, pbc::RepeatedField <string> typeList, bool hasTypeList, string connectionId)
        {
            TablesRequest req = new TablesRequest
            {
                Catalog          = catalog,
                SchemaPattern    = schemaPattern,
                TableNamePattern = tableNamePattern,
                HasTypeList      = hasTypeList,
                ConnectionId     = connectionId
            };

            req.TypeList.AddRange(typeList);

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

            using (Response webResponse = await PostRequestAsync(msg.ToByteArray()))
            {
                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(
                                  "TablesRequestAsync 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());
                    ResultSetResponse res    = ResultSetResponse.Parser.ParseFrom(output.WrappedMessage);
                    return(res);
                }
            }
        }
Exemplo n.º 8
0
        private string BuildStatement()
        {
            ResultSetResponse resp      = _connection.InternalColumnsRequest(string.Empty, string.Empty, this.DestinationTableName, string.Empty);
            string            sqlFmt    = "UPSERT INTO {0} ({1}) VALUES ({2})";
            StringBuilder     colList   = new StringBuilder();
            StringBuilder     paramList = new StringBuilder();
            int  colNameNdx             = GetNdxOfColumn(resp, "COLUMN_NAME");
            int  position = 1;
            bool bComma   = false;

            // Build positional parameter list
            foreach (var r in resp.FirstFrame.Rows)
            {
                if (bComma)
                {
                    colList.Append(",");
                    paramList.Append(",");
                }

                // Column name into list.
                string colName = r.Value[colNameNdx].Value[0].StringValue;
                colList.Append(colName);

                // Parameter or Sequence?
                if (this.ColumnMappings.ContainsKey(colName))
                {
                    paramList.Append(this.ColumnMappings[colName].DefaultValue);
                }
                else
                {
                    paramList.AppendFormat(":{0}", position++);
                }

                bComma = true;
            }

            return(string.Format(sqlFmt, this.DestinationTableName, colList, paramList));
        }