 
 
 
-(defn query [service query {:keys [max-results dry-run? max-wait-millis use-cache? default-dataset] :as query-opts}]
+(defn query
+  "Executes a query. BigQuery will create a Query Job and block for the
+  specified timeout. If the query returns within the time the results
+  will be returned. Otherwise, results need to be retrieved separately
+  using query-results. Status of the job can be checked using the job
+  function, and checking completed?"
+  [service query {:keys [max-results dry-run? max-wait-millis use-cache? default-dataset] :as query-opts}]
   (let [builder (QueryRequest/builder query)]
     (when default-dataset
       (let [{:keys [project-id dataset-id]} default-dataset]




(defn job [service {:keys [project-id job-id] :as job}]
  (to-clojure (.getJob service (JobId/of project-id job-id) (into-array BigQuery$JobOption []))))

(def create-dispositions {:needed JobInfo$CreateDisposition/CREATE_IF_NEEDED
                          :never  JobInfo$CreateDisposition/CREATE_NEVER})

(ns gclouj.bigquery
  (:require [clojure.walk :as walk])
  (:import [com.google.cloud.bigquery BigQueryOptions BigQuery$DatasetListOption DatasetInfo DatasetId BigQuery$TableListOption StandardTableDefinition TableId BigQuery$DatasetOption BigQuery$TableOption Schema Field Field$Type Field$Mode StandardTableDefinition$StreamingBuffer InsertAllRequest InsertAllRequest$RowToInsert InsertAllResponse BigQueryError BigQuery$DatasetDeleteOption QueryRequest QueryResponse QueryResult JobId Field Field$Type$Value FieldValue FieldValue$Attribute LoadConfiguration BigQuery$JobOption JobInfo$CreateDisposition JobInfo$WriteDisposition JobStatistics JobStatistics$LoadStatistics JobStatus JobStatus$State FormatOptions UserDefinedFunction JobInfo LoadJobConfiguration QueryJobConfiguration QueryJobConfiguration$Priority Table BigQuery$QueryResultsOption]
           [com.google.common.hash Hashing]
           [java.util List Collections]))

