cor*_*yes 1 clojure google-bigquery
我目前在用 Clojure 编写的后端工作。简而言之,我正在尝试将一些数据存储到 BigQuery 中,但是当我尝试创建数据集时,会出现标题中报告的错误。这里有一些代码:
(defn create-service []
(.getService (BigQueryOptions/getDefaultInstance)))
Run Code Online (Sandbox Code Playgroud)
(defn create-dataset [dataset-name]
"Given a name, it creates a dataset in BigQuery"
(println "creating a dataset called: " dataset-name)
(def bigquery (create-service))
(def dataset-info (.build (DatasetInfo/newBuilder dataset-name)))
(.create bigquery dataset-info)
)
Run Code Online (Sandbox Code Playgroud)
我也在 BigQueryImpl 中尝试了其他方法,将库降级,但结果是一样的。
堆栈跟踪:
java.lang.IllegalArgumentException: No matching method found: create for class com.google.cloud.bigquery.BigQueryImpl, compiling:(main.clj:172:24)
Exception in thread "main" java.lang.IllegalArgumentException: No matching method found: create for class com.google.cloud.bigquery.BigQueryImpl, compiling:(main.clj:172:24)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3657)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3651)
at clojure.lang.Compiler.compile1(Compiler.java:7474)
at clojure.lang.Compiler.compile(Compiler.java:7541)
at clojure.lang.RT.compile(RT.java:406)
at clojure.lang.RT.load(RT.java:451)
at clojure.lang.RT.load(RT.java:419)
at clojure.core$load$fn__5677.invoke(core.clj:5893)
at clojure.core$load.invokeStatic(core.clj:5892)
at clojure.core$load.doInvoke(core.clj:5876)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invokeStatic(core.clj:5697)
at clojure.core$compile$fn__5682.invoke(core.clj:5903)
at clojure.core$compile.invokeStatic(core.clj:5903)
at clojure.core$compile.invoke(core.clj:5895)
at user$eval20$fn__29.invoke(form-init4156994521630280254.clj:1)
at user$eval20.invokeStatic(form-init4156994521630280254.clj:1)
at user$eval20.invoke(form-init4156994521630280254.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No matching method found: create for class com.google.cloud.bigquery.BigQueryImpl
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:53)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)
at gc_webapp.persistence.gcs$create_dataset.invokeStatic(gcs.clj:177)
at gc_webapp.persistence.gcs$create_dataset.invoke(gcs.clj:168)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3652)
... 35 more
Compilation failed: Subprocess failed
Run Code Online (Sandbox Code Playgroud)
我希望有人可以帮助我。提前致谢!
PS:我是 Clojure 的初学者
如果您查看 BigQuery 接口的文档,您会发现该create方法实际上具有 Java 的可变参数签名思想:
Dataset create(DatasetInfo datasetInfo, BigQuery.DatasetOption... options)
Run Code Online (Sandbox Code Playgroud)
这实际上是(在 JVM 级别)另一个必需参数,它在调用站点由 Java语言自动填充。在 Clojure 中,您必须明确提供它以匹配签名:
(.create bigquery dataset-info (into-array BigQuery$DatasetOption []))
Run Code Online (Sandbox Code Playgroud)
旁注:def始终创建全局定义。在非顶级的任何地方使用它几乎总是错误的。改用let标准格式:
(defn create-dataset [dataset-name]
"Given a name, it creates a dataset in BigQuery"
(println "creating a dataset called: " dataset-name)
(let [bigquery (create-service)
dataset-info (.build (DatasetInfo/newBuilder dataset-name))]
(.create bigquery dataset-info (into-array BigQuery$DatasetOption [])))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |