|
24 | 24 | import com.google.api.services.bigquery.model.TableReference; |
25 | 25 | import com.google.cloud.bigquery.RangePartitioning; |
26 | 26 | import com.google.cloud.bigquery.StandardTableDefinition; |
| 27 | +import com.google.cloud.bigquery.TableDefinition; |
27 | 28 | import com.google.cloud.bigquery.TableDefinition.Type; |
28 | 29 | import com.google.cloud.bigquery.TimePartitioning; |
29 | 30 | import com.google.cloud.hadoop.io.bigquery.AbstractBigQueryInputFormat; |
@@ -139,7 +140,7 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc |
139 | 140 | datasetProjectId, datasetId, tableName, serviceAccount, isServiceAccountFilePath, null); |
140 | 141 | Type type = Objects.requireNonNull(bigQueryTable).getDefinition().getType(); |
141 | 142 | Boolean isPartitionFilterRequired = bigQueryTable.getRequirePartitionFilter(); |
142 | | - StandardTableDefinition tableDefinition = Objects.requireNonNull(bigQueryTable).getDefinition(); |
| 143 | + TableDefinition tableDefinition = Objects.requireNonNull(bigQueryTable).getDefinition(); |
143 | 144 |
|
144 | 145 | String query; |
145 | 146 | if (type == Type.VIEW || type == Type.MATERIALIZED_VIEW || type == Type.EXTERNAL) { |
@@ -173,14 +174,21 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc |
173 | 174 | @VisibleForTesting |
174 | 175 | String generateQuery(String partitionFromDate, String partitionToDate, String filter, |
175 | 176 | String datasetProject, String dataset, String table, String limit, String orderBy, |
176 | | - Boolean isPartitionFilterRequired, StandardTableDefinition tableDefinition) { |
| 177 | + Boolean isPartitionFilterRequired, TableDefinition tableDef) { |
177 | 178 |
|
178 | 179 | if (Strings.isNullOrEmpty(filter) && Strings.isNullOrEmpty(orderBy) && Strings.isNullOrEmpty( |
179 | 180 | limit) |
180 | 181 | && Strings.isNullOrEmpty(partitionFromDate) && Strings.isNullOrEmpty(partitionToDate)) { |
181 | 182 | return null; |
182 | 183 | } |
183 | 184 |
|
| 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; |
184 | 192 | RangePartitioning rangePartitioning = tableDefinition.getRangePartitioning(); |
185 | 193 | TimePartitioning timePartitioning = tableDefinition.getTimePartitioning(); |
186 | 194 | StringBuilder condition = new StringBuilder(); |
|
0 commit comments