     (.location builder (or (locations location) "US"))
     (to-clojure (.create service (.build builder) (into-array BigQuery$DatasetOption [])))))
 
+(defn delete-dataset [service {:keys [project-id dataset-id delete-contents?] :as dataset}]
+  (let [options (if delete-contents?
+                  [(BigQuery$DatasetDeleteOption/deleteContents)]
+                  [])]
+    (.delete service
+             (DatasetId/of project-id dataset-id)
+             (into-array BigQuery$DatasetDeleteOption options))))
+
 (defn- mkfield [{:keys [name type description mode fields]}]
   (let [field-type (condp = type
                      :bool      (Field$Type/bool)

(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 [_]))

                                (map (fn [[idx errors]]
                                       {:index  idx
                                        :errors (map to-clojure errors)}))
                                (seq))})
  JobId
  (to-clojure [x] {:project-id (.project x)
                   :job-id     (.job x)})
  Field
  (to-clojure [x] {:name (.name x)
                   :mode ({Field$Mode/NULLABLE :nullable
                           Field$Mode/REPEATED :repeated
                           Field$Mode/REQUIRED :required} (.mode x))
                   :type ({Field$Type$Value/BOOLEAN   :bool
                           Field$Type$Value/FLOAT     :float
                           Field$Type$Value/INTEGER   :integer
                           Field$Type$Value/RECORD    :record
                           Field$Type$Value/STRING    :string
                           Field$Type$Value/TIMESTAMP :timestamp} (.. x type value))})
  FieldValue
  (to-clojure [x] (field-value->clojure (.attribute x) x))
  Schema
  (to-clojure [x] (map to-clojure (.fields x)))
  QueryResponse
  (to-clojure [x] {:completed? (.jobCompleted x)
                   :errors     (->> (.executionErrors x) (map to-clojure) (seq))
                   :job-id     (to-clojure (.jobId x))
                   :results    (map (fn [fields] (map to-clojure fields))
                                    (iterator-seq (.. x result iterateAll)))
                   :schema     (to-clojure (.. x result schema))
                   :cache-hit  (.. x result cacheHit)}))

(defn service
  ([] (.service (BigQueryOptions/defaultInstance))))
