          (.build)
          (.insertAll service)
          (to-clojure))))
+
+
+
+(defn query [service query {:keys [project-id dataset-id] :as dataset} {:keys [max-results dry-run? max-wait-millis use-cache?] :as query-opts}]
+  (let [builder (QueryRequest/builder query)]
+    (.defaultDataset builder (DatasetId/of project-id dataset-id))
+    (when max-results
+      (.maxResults builder max-results))
+    (when dry-run?
+      (.dryRun builder dry-run?))
+    (when max-wait-millis
+      (.maxWaitTime builder max-wait-millis))
+    (when use-cache?
+      (.useQueryCache builder use-cache?))
+    (let [q (.build builder)]
+      (to-clojure (.query service q)))))

(ns gclouj.bigquery
  (:import [com.google.gcloud.bigquery BigQueryOptions BigQuery$DatasetListOption DatasetInfo DatasetId BigQuery$TableListOption TableInfo TableId BigQuery$DatasetOption BigQuery$TableOption Schema Field Field$Type Field$Mode TableInfo$StreamingBuffer InsertAllRequest InsertAllRequest$RowToInsert InsertAllResponse BigQueryError]
           [com.google.common.hash Hashing]))

(defprotocol ToClojure
  (to-clojure [_]))

        table-info (.build builder)]
    (to-clojure (.create service table-info (into-array BigQuery$TableOption [])))))

(defn delete-table
  [service {:keys [project-id dataset-id table-id] :as table}]
  (.delete service (TableId/of project-id dataset-id table-id)))

(defn row-hash
  "Creates a hash suitable for identifying duplicate rows, useful when
  streaming to avoid inserting duplicate rows."
