此問題是this one的後續行爲。 我想使用Apache梁從谷歌扳手錶中讀取數據(然後做一些數據處理)。在apache光束中使用SpannerIO時出錯
package com.google.cloud.dataflow.examples;
import java.io.IOException;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.PipelineResult;
import org.apache.beam.sdk.io.gcp.spanner.SpannerIO;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.apache.beam.sdk.values.PCollection;
import com.google.cloud.spanner.Struct;
public class backup {
public static void main(String[] args) throws IOException {
PipelineOptions options = PipelineOptionsFactory.create();
Pipeline p = Pipeline.create(options);
PCollection<Struct> rows = p.apply(
SpannerIO.read()
.withInstanceId("my_instance")
.withDatabaseId("my_db")
.withQuery("SELECT t.table_name FROM information_schema.tables AS t")
);
PipelineResult result = p.run();
try {
result.waitUntilFinish();
} catch (Exception exc) {
result.cancel();
}
}
}
當我嘗試使用DirectRunner執行代碼時,我得到了 以下錯誤消息:
org.apache.beam.runners.direct我使用了Java SDK寫了下面的最低例子.repackaged.com.google.common.util.concurrent.UncheckedExecutionException:
org.apache.beam.sdk.util.UserCodeException: java.lang.NoClassDefFoundError: Could not initialize class com.google.cloud.spanner.spi.v1.SpannerErrorInterceptor
[...] Caused by: org.apache.beam.sdk.util.UserCodeException: java.lang.NoClassDefFoundError: Could not initialize class com.google.cloud.spanner.spi.v1.SpannerErrorInterceptor
[...] Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.cloud.spanner.spi.v1.SpannerErrorInterceptor
或者使用DataflowRunner:
org.apache.beam.runners.direct.repackaged.com.google.common.util.concurrent.UncheckedExecutionException: org.apache.beam.sdk.util.UserCodeException: java.lang.NoSuchFieldError: internal_static_google_rpc_LocalizedMessage_fieldAccessorTable
[...] Caused by: org.apache.beam.sdk.util.UserCodeException: java.lang.NoSuchFieldError: internal_static_google_rpc_LocalizedMessage_fieldAccessorTable
[...] Caused by: java.lang.NoSuchFieldError: internal_static_google_rpc_LocalizedMessage_fieldAccessorTable
在這兩種情況下,錯誤信息都很隱祕,而且我無法找到任何關於Google搜索錯誤的原因。我也無法使用SpannerIO模塊找到任何示例腳本。
此錯誤是由於我的代碼中的明顯錯誤,還是由於谷歌雲工具的安裝不當造成的?
Argh,你很可能觸及依賴衝突https://issues.apache.org/jira/browse/BEAM-2837。它是固定的,但我們需要等待新版本的光束。您可以從源代碼自己構建光束二進制文件,或者在您的pom.xml中使用這個技巧https://gist.github.com/mairbek/0c770ff7b591e3db58936b0b9294215a –
哦。謝謝 !我想我會嘗試修復。 –