   (to-clojure [x] {:location          (.location x)
                    :bytes             (.numBytes x)
                    :rows              (.numRows x)
-                   :streaming-buffer  (when-let [sb (.streamingBuffer x)]
-                                        (to-clojure sb))
-                   :schema            (to-clojure (.schema x))})
+                   :streaming-buffer  (when-let [sb (.streamingBuffer x)] (to-clojure sb))
+                   :schema            (when-let [schema (.schema x)] (to-clojure schema))})
+  ViewDefinition
+  (to-clojure [x] {:schema (when-let [schema (.schema x)]
+                             (to-clojure schema))})
   Table
   (to-clojure [x] {:creation-time (.creationTime x)
                    :description   (.description x)

(ns gclouj.bigquery
  (:require [clojure.walk :as walk]
            [clj-time.coerce :as tc])
  (: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 TableInfo]
           [com.google.common.hash Hashing]
           [java.util List Collections]
           [java.util.concurrent TimeUnit]))

                         :truncate JobInfo$WriteDisposition/WRITE_TRUNCATE})

(defn load-job
  "Loads data from Cloud Storage URIs into the specified table. Options:
  `create-disposition` controls whether tables are created if
  necessary, or assume to have been created already (default).
  `write-disposition`  controls whether data should :append (default),
  :truncate or :empty to fail if table exists.
  :format              :json or :csv
  :schema              sequence describing the table schema.[{:name \"foo\" :type :record :fields [{:name \"bar\" :type :integer}]}]"
  [service {:keys [project-id dataset-id table-id] :as table} {:keys [format create-disposition write-disposition max-bad-records schema]} uris]
  (let [builder (LoadJobConfiguration/builder (TableId/of project-id dataset-id table-id)
                                              uris
                                              ({:json (FormatOptions/json)
