Skip to content

Commit 88aee75

Browse files
Merge pull request #1618 from data-integrations/hyphen-fix
Added fix for an error when table name was having hyphens and source transfers were failing.
2 parents 0dbe192 + 63096a8 commit 88aee75

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ String generateQuery(String partitionFromDate, String partitionToDate, String fi
228228
}
229229
}
230230

231-
String tableName = datasetProject + "." + dataset + "." + table;
231+
String tableName = String.format("`%s.%s.%s`", datasetProject, dataset, table);
232232
StringBuilder query = new StringBuilder("select * from ").append(tableName);
233233

234234
if (condition.length() > 0) {

src/test/java/io/cdap/plugin/gcp/bigquery/source/PartitionedBigQueryInputFormatTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020 Cask Data, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -116,7 +116,7 @@ public void testGenerateQueryForMaterializingView_AllOptions() {
116116

117117
@Test
118118
public void testGenerateQuery_WithFilterOnly() {
119-
String expectedQuery = String.format("select * from %s where %s",
119+
String expectedQuery = String.format("select * from `%s` where %s",
120120
TEST_TABLE_SPEC, TEST_FILTER);
121121

122122
String generatedQuery = format.generateQuery(null, null,
@@ -128,7 +128,7 @@ public void testGenerateQuery_WithFilterOnly() {
128128

129129
@Test
130130
public void testGenerateQuery_AllOptions() {
131-
String expectedQuery = String.format("select * from %s where %s order by %s limit %s",
131+
String expectedQuery = String.format("select * from `%s` where %s order by %s limit %s",
132132
TEST_TABLE_SPEC, TEST_FILTER, TEST_ORDER_BY, TEST_LIMIT);
133133

134134
String generatedQuery = format.generateQuery(null, null,
@@ -143,7 +143,7 @@ public void testGenerateQuery_TimePartitionWithDates() {
143143
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
144144
when(mockTimePartitioning.getField()).thenReturn(null);
145145

146-
String expectedQuery = String.format("select * from %s where (%s)",
146+
String expectedQuery = String.format("select * from `%s` where (%s)",
147147
TEST_TABLE_SPEC,
148148
TEST_PARTITION_CONDITION);
149149

@@ -158,7 +158,7 @@ public void testGenerateQuery_TimePartitionWithDates() {
158158
public void testGenerateQuery_TimePartitionRequiredAndFilter() {
159159
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
160160
when(mockTimePartitioning.getField()).thenReturn(null);
161-
String expectedQuery = String.format("select * from %s where %s and (%s)",
161+
String expectedQuery = String.format("select * from `%s` where %s and (%s)",
162162
TEST_TABLE_SPEC, TEST_DEFAULT_TIME_CONDITION, TEST_FILTER);
163163

164164
String generatedQuery = format.generateQuery(null, null,
@@ -177,7 +177,7 @@ public void testGenerateQuery_TimeUnitPartitionWithDates() {
177177
when(mockFieldList.get(TEST_TIME_UNIT_COL)).thenReturn(mockField);
178178
when(mockField.getType()).thenReturn(LegacySQLTypeName.DATE);
179179

180-
String expectedQuery = String.format("select * from %s where (%s)",
180+
String expectedQuery = String.format("select * from `%s` where (%s)",
181181
TEST_TABLE_SPEC, TEST_TIME_UNIT_PARTITION_CONDITION);
182182

183183
String generatedQuery = format.generateQuery(TEST_FROM_DATE, TEST_TO_DATE, null,
@@ -192,7 +192,7 @@ public void testGenerateQuery_TimePartitionFilterNotRequiredWithDates() {
192192
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
193193
when(mockTimePartitioning.getField()).thenReturn(null);
194194

195-
String expectedQuery = String.format("select * from %s where (%s)",
195+
String expectedQuery = String.format("select * from `%s` where (%s)",
196196
TEST_TABLE_SPEC,
197197
TEST_PARTITION_CONDITION);
198198

@@ -214,7 +214,7 @@ public void testGenerateQuery_NoOptions_ShouldReturnNull() {
214214

215215
@Test
216216
public void testGenerateQuery_WithLimitOnly_ShouldAssertQuery() {
217-
String expectedQuery = String.format("select * from %s limit %s", TEST_TABLE_SPEC,
217+
String expectedQuery = String.format("select * from `%s` limit %s", TEST_TABLE_SPEC,
218218
TEST_LIMIT);
219219

220220
String generatedQuery = format.generateQuery(null, null,
@@ -226,7 +226,7 @@ public void testGenerateQuery_WithLimitOnly_ShouldAssertQuery() {
226226

227227
@Test
228228
public void testGenerateQuery_WithOrderByOnly_ShouldAssertQuery() {
229-
String expectedQuery = String.format("select * from %s order by %s", TEST_TABLE_SPEC,
229+
String expectedQuery = String.format("select * from `%s` order by %s", TEST_TABLE_SPEC,
230230
TEST_ORDER_BY);
231231

232232
String generatedQuery = format.generateQuery(null, null,
@@ -241,7 +241,7 @@ public void testGenerateQuery_TimePartitionNotRequired_WithDates_ShouldAssertQue
241241
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
242242
when(mockTimePartitioning.getField()).thenReturn(null);
243243

244-
String expectedQuery = String.format("select * from %s where (%s)",
244+
String expectedQuery = String.format("select * from `%s` where (%s)",
245245
TEST_TABLE_SPEC,
246246
TEST_PARTITION_CONDITION);
247247

@@ -257,7 +257,7 @@ public void testGenerateQuery_TimePartitionRequired_WithFilterOnly_ShouldAssertQ
257257
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
258258
when(mockTimePartitioning.getField()).thenReturn(null);
259259

260-
String expectedQuery = String.format("select * from %s where %s and (%s)",
260+
String expectedQuery = String.format("select * from `%s` where %s and (%s)",
261261
TEST_TABLE_SPEC, TEST_DEFAULT_TIME_CONDITION, TEST_FILTER);
262262

263263
String generatedQuery = format.generateQuery(null, null,
@@ -272,7 +272,7 @@ public void testGenerateQuery_RangePartitionRequiredAndFilter() {
272272
when(mockTableDefinition.getRangePartitioning()).thenReturn(mockRangePartitioning);
273273
when(mockRangePartitioning.getField()).thenReturn("range_col");
274274

275-
String expectedQuery = String.format("select * from %s where %s and (%s)",
275+
String expectedQuery = String.format("select * from `%s` where %s and (%s)",
276276
TEST_TABLE_SPEC, TEST_DEFAULT_RANGE_CONDITION, TEST_FILTER);
277277

278278
String generatedQuery = format.generateQuery(null, null, TEST_FILTER,
@@ -287,7 +287,7 @@ public void testGenerateQuery_RangePartitionRequiredWithLimit() {
287287
when(mockTableDefinition.getRangePartitioning()).thenReturn(mockRangePartitioning);
288288
when(mockRangePartitioning.getField()).thenReturn("range_col");
289289

290-
String expectedQuery = String.format("select * from %s where %s limit %s",
290+
String expectedQuery = String.format("select * from `%s` where %s limit %s",
291291
TEST_TABLE_SPEC, TEST_DEFAULT_RANGE_CONDITION, TEST_LIMIT);
292292

293293
String generatedQuery = format.generateQuery(null, null, null,
@@ -302,7 +302,7 @@ public void testGenerateQuery_TimeUnitPartitionRequiredAndFilter() {
302302
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
303303
when(mockTimePartitioning.getField()).thenReturn(TEST_TIME_UNIT_COL);
304304

305-
String expectedQuery = String.format("select * from %s where %s and (%s)",
305+
String expectedQuery = String.format("select * from `%s` where %s and (%s)",
306306
TEST_TABLE_SPEC, TEST_DEFAULT_TIME_UNIT_CONDITION, TEST_FILTER);
307307

308308
String generatedQuery = format.generateQuery(null, null, TEST_FILTER,
@@ -317,7 +317,7 @@ public void testGenerateQuery_TimeUnitPartitionRequiredWithLimit() {
317317
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
318318
when(mockTimePartitioning.getField()).thenReturn(TEST_TIME_UNIT_COL);
319319

320-
String expectedQuery = String.format("select * from %s where %s limit %s",
320+
String expectedQuery = String.format("select * from `%s` where %s limit %s",
321321
TEST_TABLE_SPEC, TEST_DEFAULT_TIME_UNIT_CONDITION, TEST_LIMIT);
322322

323323
String generatedQuery = format.generateQuery(null, null, null,

0 commit comments

Comments
 (0)