Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/main/java/io/cdap/plugin/gcp/bigquery/util/BigQueryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,18 +802,27 @@ public static String generateTimePartitionCondition(StandardTableDefinition tabl
*
* @param datasetProject Name of the BQ project
* @param datasetName Name of the BQ dataset
* @param tableName Name of the BQ table
* @param tableName Name of the BQ table, If null, only project and dataset are included.
* @return String fqn
*/
public static String getFQN(String datasetProject, String datasetName, String tableName) {
public static String getFQN(String datasetProject, String datasetName,
@Nullable String tableName) {

String formattedProject = GCPUtils.formatAsFQNComponent(datasetProject);
String formattedDataset = GCPUtils.formatAsFQNComponent(datasetName);
String formattedTable = GCPUtils.formatAsFQNComponent(tableName);
StringBuilder fqnBuilder = new StringBuilder(BigQueryConstants.BQ_FQN_PREFIX)
.append(":")
.append(formattedProject)
.append(".")
.append(formattedDataset);

if (tableName != null) {
String formattedTable = GCPUtils.formatAsFQNComponent(tableName);
fqnBuilder.append(".").append(formattedTable);
}

String fqn = String.format("%s:%s.%s.%s", BigQueryConstants.BQ_FQN_PREFIX, formattedProject,
formattedDataset, formattedTable);
LOG.trace("Formatted Fully-Qualified Name (FQN): {}", fqn);
String fqn = fqnBuilder.toString();
LOG.trace("Constructed Fully-Qualified Name (FQN): {}", fqn);
return fqn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ public void testGetFQNWithReservedCharacters() {
Assert.assertEquals(result, expectedFQN);
}

@Test
public void testGetFQNWithNullTableName() {
String datasetProject = "project";
String datasetName = "dataset";
String tableName = null;
String expectedFQN = "bigquery:project.dataset";

String result = BigQueryUtil.getFQN(datasetProject, datasetName, tableName);
Assert.assertEquals(result, expectedFQN);
}

@Test
public void testGetFQNWithoutReservedCharacters() {
String datasetProject = "project";
Expand Down
Loading