[ 
https://issues.apache.org/jira/browse/BEAM-6474?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Graham Polley closed BEAM-6474.
-------------------------------
       Resolution: Not A Problem
    Fix Version/s: 2.9.0

Closing. Easy to fix with an alias in the SQL string.

> Cannot reference field when using SqlTransform (need to use "EXPR$N" instead)
> -----------------------------------------------------------------------------
>
>                 Key: BEAM-6474
>                 URL: https://issues.apache.org/jira/browse/BEAM-6474
>             Project: Beam
>          Issue Type: Bug
>          Components: dsl-sql
>    Affects Versions: 2.9.0
>         Environment: MacOS
>            Reporter: Graham Polley
>            Assignee: Graham Polley
>            Priority: Minor
>             Fix For: 2.9.0
>
>
> Maybe I've done something wrong, but when you try to access a field this has 
> been generated in a SqlTransform it throws an exception:
>  
> {code:java}
> java.lang.RuntimeException: org.apache.beam.sdk.util.UserCodeException: 
> java.lang.IllegalArgumentException: Cannot find field views in schema Fields: 
> Field{name=wikimedia_project, description=, type=FieldType{typeName=STRING, 
> collectionElementType=null, collectionElementTypeNullable=null, 
> mapKeyType=null, mapValueType=null, mapValueTypeNullable=null, 
> rowSchema=null, metadata=null}, nullable=false} Field{name=EXPR$1, 
> description=, type=FieldType{typeName=INT32, collectionElementType=null, 
> collectionElementTypeNullable=null, mapKeyType=null, mapValueType=null, 
> mapValueTypeNullable=null, rowSchema=null, metadata=null}, 
> nullable=false}{code}
> Instead of being able to access the `views` field, it has been named `EXPR$1` 
> by Beam/Dataflow. So, to get the value of the field I need to do this:
> {code:java}
> bqRow.set("views", row.getInt32("EXPR$1"));{code}
> instead of:
> {code:java}
> bqRow.set("views", row.getInt32("views"));{code}
>  
> {code:java}
> PCollection<Row> outputStream =
>  sqlRows.setRowSchema(SCHEMA)
>  .apply("sql_transform",
>  SqlTransform.query(
>  "select wikimedia_project, sum(views) " +
>  "from PCOLLECTION " +
>  "group by wikimedia_project"));{code}
>  
> Pipeline is reading a file from GCS, transforming it (using SqlTransform) and 
> writing to BigQuery. Code can be found here:
> [https://github.com/polleyg/gcp-batch-ingestion-bigquery/blob/beam_sql/src/main/java/org/polleyg/TemplatePipeline.java]
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to