Skip to content

Commit 889b710

Browse files
authored
Merge pull request #1609 from data-integrations/cherry-pick-23-1607
[🍒 ] Fix ClassCastException in BigQuery source plugin for table definition
2 parents 92729c2 + 58f108f commit 889b710

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<groupId>io.cdap.plugin</groupId>
2222
<artifactId>google-cloud</artifactId>
23-
<version>0.23.6</version>
23+
<version>0.23.7-SNAPSHOT</version>
2424
<name>Google Cloud Plugins</name>
2525
<packaging>jar</packaging>
2626
<description>Plugins for Google Big Query</description>

src/main/java/io/cdap/plugin/gcp/bigquery/source/PartitionedBigQueryInputFormat.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.api.services.bigquery.model.TableReference;
2525
import com.google.cloud.bigquery.RangePartitioning;
2626
import com.google.cloud.bigquery.StandardTableDefinition;
27+
import com.google.cloud.bigquery.TableDefinition;
2728
import com.google.cloud.bigquery.TableDefinition.Type;
2829
import com.google.cloud.bigquery.TimePartitioning;
2930
import com.google.cloud.hadoop.io.bigquery.AbstractBigQueryInputFormat;
@@ -139,7 +140,7 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc
139140
datasetProjectId, datasetId, tableName, serviceAccount, isServiceAccountFilePath, null);
140141
Type type = Objects.requireNonNull(bigQueryTable).getDefinition().getType();
141142
Boolean isPartitionFilterRequired = bigQueryTable.getRequirePartitionFilter();
142-
StandardTableDefinition tableDefinition = Objects.requireNonNull(bigQueryTable).getDefinition();
143+
TableDefinition tableDefinition = Objects.requireNonNull(bigQueryTable).getDefinition();
143144

144145
String query;
145146
if (type == Type.VIEW || type == Type.MATERIALIZED_VIEW || type == Type.EXTERNAL) {
@@ -173,14 +174,21 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc
173174
@VisibleForTesting
174175
String generateQuery(String partitionFromDate, String partitionToDate, String filter,
175176
String datasetProject, String dataset, String table, String limit, String orderBy,
176-
Boolean isPartitionFilterRequired, StandardTableDefinition tableDefinition) {
177+
Boolean isPartitionFilterRequired, TableDefinition tableDef) {
177178

178179
if (Strings.isNullOrEmpty(filter) && Strings.isNullOrEmpty(orderBy) && Strings.isNullOrEmpty(
179180
limit)
180181
&& Strings.isNullOrEmpty(partitionFromDate) && Strings.isNullOrEmpty(partitionToDate)) {
181182
return null;
182183
}
183184

185+
if (!(tableDef instanceof StandardTableDefinition)) {
186+
throw new IllegalArgumentException(
187+
String.format("Unsupported BigQuery table type for filtering/partitioning: %s. " +
188+
"Cannot apply filters, limits, or ordering.", tableDef.getType()));
189+
}
190+
191+
StandardTableDefinition tableDefinition = (StandardTableDefinition) tableDef;
184192
RangePartitioning rangePartitioning = tableDefinition.getRangePartitioning();
185193
TimePartitioning timePartitioning = tableDefinition.getTimePartitioning();
186194
StringBuilder condition = new StringBuilder();

0 commit comments

Comments
 (0)