public static async Task <SchemaBuilder> FromTableInfosAsync(BigQueryContext context, DriverProperty property)
        {
            string[] datasets;
            if (property.ContextIsOnlyDataSet)
            {
                datasets = new[] { property.ContextDataSet };
            }
            else
            {
                datasets = await context.GetAllDatasetsAsync();
            }

            var list = new List <Schema>();

            foreach (var dataset in datasets)
            {
                var tables = await context.GetFastTableSchemasAsync(dataset);

                var schema = new Schema()
                {
                    DatasetName             = dataset,
                    GroupedMetaTableSchemas = tables,
                };

                list.Add(schema);
            }

            return(new SchemaBuilder(context, property, list.ToArray()));
        }
Exemple #2
0
        public static BigQueryContext GetContext(string json, string user, string projectId)
        {
            BigQueryContext context;

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
            {
                // Open Browser, Accept Auth
                var userCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(ms,
                                                                                 new[] { BigqueryService.Scope.Bigquery },
                                                                                 user,
                                                                                 CancellationToken.None, new FileDataStore(@"LINQ-to-BigQuery-for-" + projectId)) // localcache
                                     .GetAwaiter().GetResult();

                var bigquery = new BigqueryService(new BaseClientService.Initializer
                {
                    ApplicationName       = "LINQ to BigQuery",
                    HttpClientInitializer = userCredential
                });

                context = new BigQueryContext(bigquery, projectId);
            }
            // Timeout or other options
            context.TimeoutMs = (long)TimeSpan.FromMinutes(3).TotalMilliseconds;
            return(context);
        }
 private QueryResponse(BigQueryContext context, string query, TimeSpan executionTime,
                       GetQueryResultsResponse queryResponse, bool isDynamic, IRowsParser rowsParser)
     : this(
         context, query, executionTime, isDynamic, rowsParser, queryResponse.Rows, queryResponse.Schema,
         queryResponse.CacheHit, queryResponse.ETag, queryResponse.Kind,
         queryResponse.PageToken, queryResponse.TotalBytesProcessed, queryResponse.TotalRows,
         queryResponse.JobComplete, queryResponse.JobReference)
 {
 }
        private JobsResource.GetQueryResultsRequest CreateNextPageRequest(BigQueryContext context,
                                                                          bool jobComplete, JobReference jobReference, string pageToken, bool hasNextPage)
        {
            if (!jobComplete)
            {
                throw new InvalidOperationException("Can't get next page for a job that has not completed");
            }

            if (!hasNextPage)
            {
                throw new InvalidOperationException("No more pages to retrieve");
            }

            var furtherRequest = context.BigQueryService.Jobs.GetQueryResults(jobReference.ProjectId, jobReference.JobId);

            furtherRequest.PageToken = pageToken;
            return(furtherRequest);
        }
Exemple #5
0
        internal QueryResponse(BigQueryContext context, string query, TimeSpan executionTime, QueryResponse queryResponse, bool isDynamic)
        {
            T[] rows;
            if (queryResponse.Rows == null)
            {
                rows = new T[0];
            }
            else if (!isDynamic)
            {
                CustomDeserializeFallback fallback;
                if (!context.fallbacks.TryGetValue(typeof(T), out fallback))
                {
                    fallback = null;
                }

                var deserializer = new Deserializer <T>(queryResponse.Schema, fallback);
                rows = queryResponse.Rows.Select(row => deserializer.Deserialize(row, context.IsConvertResultUtcToLocalTime)).ToArray();
            }
            else
            {
                rows = queryResponse.Rows.Select(row => Deserializer.DeserializeDynamic(queryResponse.Schema, row))
                       .Cast <T>() // T as dynamic...
                       .ToArray();
            }
            var schemas = (queryResponse.Schema == null)
                ? new TableFieldSchema[0]
                : queryResponse.Schema.Fields;

            this.Query               = query;
            this.CacheHit            = queryResponse.CacheHit;
            this.ETag                = queryResponse.ETag;
            this.Kind                = queryResponse.Kind;
            this.PageToken           = queryResponse.PageToken;
            this.Rows                = rows;
            this.TotalBytesProcessed = queryResponse.TotalBytesProcessed;
            this.TotalRows           = queryResponse.TotalRows;
            this.ExecutionTime       = executionTime;
            this.TableFieldSchemas   = schemas;

            this.TotalBytesProcessedFormatted = queryResponse.TotalBytesProcessed.ToHumanReadableSize();
        }
        private QueryResponse(BigQueryContext context, string query, TimeSpan executionTime, bool isDynamic,
                              IRowsParser rowsParser, IList <TableRow> rows, TableSchema schema, bool?cacheHit, string eTag, string kind,
                              string pageToken, long?totalBytesProcessed, ulong?totalRows,
                              bool?jobComplete, JobReference jobReference)
        {
            _context    = context;
            _isDynamic  = isDynamic;
            _rowsParser = rowsParser;

            Rows = rows == null
                ? new T[0]
                : rowsParser.Parse <T>(
                context.fallbacks,
                context.IsConvertResultUtcToLocalTime,
                schema,
                rows,
                isDynamic).ToArray();

            TableFieldSchemas = (schema == null)
                ? new TableFieldSchema[0]
                : schema.Fields;

            Query               = query;
            ExecutionTime       = executionTime;
            CacheHit            = cacheHit;
            ETag                = eTag;
            Kind                = kind;
            PageToken           = pageToken;
            TotalBytesProcessed = totalBytesProcessed;
            TotalRows           = totalRows;

            TotalBytesProcessedFormatted = totalBytesProcessed.ToHumanReadableSize();

            _jobComplete  = jobComplete.GetValueOrDefault(false);
            _jobReference = jobReference;
        }
Exemple #7
0
 public RootBigQueryable(BigQueryContext context)
     : base(context)
 {
 }
Exemple #8
0
 protected BigQueryable(BigQueryContext context)
 {
     this.Parent       = null;
     this.QueryContext = context;
 }
Exemple #9
0
 protected BigQueryable(IBigQueryable parent)
 {
     this.Parent       = parent;
     this.QueryContext = parent.QueryContext;
 }
 public SchemaBuilder(BigQueryContext context, DriverProperty property, Schema[] schemas)
 {
     this.context  = context;
     this.Schemas  = schemas;
     this.property = property;
 }