Skip to content

Commit 6db2c69

Browse files
Merge pull request #1522 from data-integrations/bug/null-pointer
[PLUGIN-1843] Handle Null pointer when using BQ Multi sink without reference name
2 parents dc4ce41 + 79611f3 commit 6db2c69

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/main/java/io/cdap/plugin/gcp/bigquery/util/BigQueryUtil.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -802,18 +802,27 @@ public static String generateTimePartitionCondition(StandardTableDefinition tabl
802802
*
803803
* @param datasetProject Name of the BQ project
804804
* @param datasetName Name of the BQ dataset
805-
* @param tableName Name of the BQ table
805+
* @param tableName Name of the BQ table, If null, only project and dataset are included.
806806
* @return String fqn
807807
*/
808-
public static String getFQN(String datasetProject, String datasetName, String tableName) {
808+
public static String getFQN(String datasetProject, String datasetName,
809+
@Nullable String tableName) {
809810

810811
String formattedProject = GCPUtils.formatAsFQNComponent(datasetProject);
811812
String formattedDataset = GCPUtils.formatAsFQNComponent(datasetName);
812-
String formattedTable = GCPUtils.formatAsFQNComponent(tableName);
813+
StringBuilder fqnBuilder = new StringBuilder(BigQueryConstants.BQ_FQN_PREFIX)
814+
.append(":")
815+
.append(formattedProject)
816+
.append(".")
817+
.append(formattedDataset);
818+
819+
if (tableName != null) {
820+
String formattedTable = GCPUtils.formatAsFQNComponent(tableName);
821+
fqnBuilder.append(".").append(formattedTable);
822+
}
813823

814-
String fqn = String.format("%s:%s.%s.%s", BigQueryConstants.BQ_FQN_PREFIX, formattedProject,
815-
formattedDataset, formattedTable);
816-
LOG.trace("Formatted Fully-Qualified Name (FQN): {}", fqn);
824+
String fqn = fqnBuilder.toString();
825+
LOG.trace("Constructed Fully-Qualified Name (FQN): {}", fqn);
817826
return fqn;
818827
}
819828

src/test/java/io/cdap/plugin/gcp/bigquery/util/BigQueryUtilTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ public void testGetFQNWithReservedCharacters() {
183183
Assert.assertEquals(result, expectedFQN);
184184
}
185185

186+
@Test
187+
public void testGetFQNWithNullTableName() {
188+
String datasetProject = "project";
189+
String datasetName = "dataset";
190+
String tableName = null;
191+
String expectedFQN = "bigquery:project.dataset";
192+
193+
String result = BigQueryUtil.getFQN(datasetProject, datasetName, tableName);
194+
Assert.assertEquals(result, expectedFQN);
195+
}
196+
186197
@Test
187198
public void testGetFQNWithoutReservedCharacters() {
188199
String datasetProject = "project";

0 commit comments

Comments
 (0)