我是新來的GC數據流,並沒有在這裏找到相關的答案。道歉,如果我應該發現這已經回答。谷歌雲數據流,BigQueryIO和NullPointerException異常上TableRow.get
我想創建一個使用v2.0 SDK的簡單管道,並且無法使用BigQueryIO將數據讀入我的PCollection。我正在使用.withQuery方法,並且已經在BigQuery接口中測試了這個查詢,並且它似乎工作正常。最初PCollection似乎變得沒有任何問題產生,但是當我想建立一個簡單的帕爾多函數值從的TableRow轉換成PCollection我正在上的代碼,做了的TableRow對象就不用彷徨行了一個NullPointerException。
這是我的代碼。 (我可能失去了一些東西很簡單。我在管道規劃總新手。任何投入將非常感激。)
public class ClientAutocompletePipeline {
private static final Logger LOG = LoggerFactory.getLogger(ClientAutocompletePipeline.class);
public static void main(String[] args) {
// create the pipeline
Pipeline p = Pipeline.create(
PipelineOptionsFactory.fromArgs(args).withValidation().create());
// A step to read in the product names from a BigQuery table
p.apply(BigQueryIO.read().fromQuery("SELECT name FROM [beaming-team-169321:Products.raw_product_data]"))
.apply("ExtractProductNames", ParDo.of(new DoFn<TableRow, String>() {
@ProcessElement
public void processElement(ProcessContext c) {
// Grab a row from the BigQuery Results
TableRow row = c.element();
// Get the value of the "name" column from the table row.
//NOTE: This is the line that is giving me the NullPointerException
String productName = row.get("name").toString();
// Make sure it isn't empty
if (!productName.isEmpty()) {
c.output(productName);
}
}
}))
查詢使用BigQuery UI,並呼籲列中明確作品「名」是當我測試查詢時返回。爲什麼我會在此行上發生NullPointerException:
String productName = row.get("name").toString();
任何想法?
是否所有的值的保證不會了'name'列爲空? –
如果您在BigQuery中運行'SELECT name FROM [beaming-team-169321:Products.raw_product_data] where name is null',則會看到有空值。所以,你需要在管道中考慮到這一點。 –
那麼,現在你提到它,這確實很有意義。我想我的錯誤印象是由於我的代碼中有一些錯誤導致它們全部爲空,但我想這可能不是這種情況。感謝回覆! – MrSimmonsSr