Пример #1
0
        JobsResource.QueryRequest CreateRequest() {
            BigQueryParameterCollection collection = (BigQueryParameterCollection)bigQueryCommand.Parameters;
            if(!IsStandardSql) {
                foreach(BigQueryParameter parameter in collection) {
                    bigQueryCommand.CommandText = bigQueryCommand.CommandText.Replace(parameterPrefix + parameter.ParameterName.TrimStart(parameterPrefix), ConvertToStringForLegacySql(parameter));
                }    
            }

            QueryRequest queryRequest = new QueryRequest { Query = PrepareCommandText(bigQueryCommand), TimeoutMs = bigQueryCommand.CommandTimeout != 0 ? (int)TimeSpan.FromSeconds(bigQueryCommand.CommandTimeout).TotalMilliseconds : int.MaxValue, UseLegacySql = !IsStandardSql };
            if(IsStandardSql) {
                queryRequest.QueryParameters = new List<QueryParameter>();
                foreach(BigQueryParameter parameter in collection) {
                    var queryParameter = new QueryParameter {
                        Name = parameter.ParameterName,
                        ParameterType = new QueryParameterType {
                            Type = BigQueryTypeConverter.ToParameterStringType(parameter.BigQueryDbType)
                        },
                        ParameterValue = new QueryParameterValue {Value = ConvertToString(parameter)}
                    };
                    queryRequest.QueryParameters.Add(queryParameter);
                }
            }
            
            JobsResource.QueryRequest request = bigQueryService.Jobs.Query(queryRequest, bigQueryCommand.Connection.ProjectId);
            return request;
        }
Пример #2
0
 internal async Task InitializeAsync(CancellationToken cancellationToken) {
     cancellationToken.ThrowIfCancellationRequested();
     try {
         if(behavior == CommandBehavior.SchemaOnly) {
             TableList tableList = await bigQueryService.Tables.List(bigQueryCommand.Connection.ProjectId, bigQueryCommand.Connection.DataSetId).ExecuteAsync(cancellationToken).ConfigureAwait(false);
             tables = tableList.Tables.GetEnumerator();
         } else {
             ((BigQueryParameterCollection)bigQueryCommand.Parameters).Validate();
             JobsResource.QueryRequest request = CreateRequest();
             QueryResponse queryResponse = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);
             ProcessQueryResponse(queryResponse);
         }
     }
     catch(GoogleApiException e) {
         throw e.Wrap();
     }
 }
Пример #3
0
        // [END paging]

        /// <summary>Perform the given query using the synchronous api.
        /// </summary>
        /// <param name="projectId">project id from developer console</param>
        /// <param name="queryString">query to run</param>
        /// <param name="timeoutMs">Timeout in milliseconds before we abort
        /// </param>
        /// <returns>The results of the query</returns>
        /// <exception cref="TimeoutException">If the request times out.
        /// </exception>
        // [START sync_query]
        public IEnumerable <TableRow> SyncQuery(string projectId,
                                                string queryString, long timeoutMs)
        {
            BigqueryService bigquery = CreateAuthorizedClient();
            var             query    = new JobsResource.QueryRequest(
                bigquery, new QueryRequest()
            {
                Query     = queryString,
                TimeoutMs = timeoutMs,
            }, projectId).Execute();

            if (query.JobComplete != true)
            {
                throw new TimeoutException();
            }
            return(query.Rows ?? new TableRow[] { });
        }
Пример #4
0
 // [END paging]
 /// <summary>Perform the given query using the synchronous api.</summary>
 /// <param name="projectId">project id from developer console</param>
 /// <param name="queryString">query to run</param>
 /// <param name="timeoutMs">Timeout in milliseconds before we abort</param>
 /// <returns>The results of the query</returns>
 /// <exception cref="TimeoutException">If the request times out.</exception>
 // [START sync_query]
 public static IEnumerable<TableRow> SyncQuery(BigqueryService bigquery,
     string projectId, string queryString, long timeoutMs)
 {
     var query = new JobsResource.QueryRequest(
         bigquery, new QueryRequest()
         {
             Query = queryString,
             TimeoutMs = timeoutMs,
         }, projectId).Execute();
     if (query.JobComplete != true)
         throw new TimeoutException();
     return query.Rows ?? new TableRow[] { };
 }