Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ String generateQuery(String partitionFromDate, String partitionToDate, String fi
}
}

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

if (condition.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright © 2020 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
Expand Down Expand Up @@ -114,7 +114,7 @@ public void testGenerateQueryForMaterializingView_AllOptions() {

@Test
public void testGenerateQuery_WithFilterOnly() {
String expectedQuery = String.format("select * from %s where %s",
String expectedQuery = String.format("select * from `%s` where %s",
TEST_TABLE_SPEC, TEST_FILTER);

String generatedQuery = format.generateQuery(null, null,
Expand All @@ -126,7 +126,7 @@ public void testGenerateQuery_WithFilterOnly() {

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

String generatedQuery = format.generateQuery(null, null,
Expand All @@ -141,7 +141,7 @@ public void testGenerateQuery_TimePartitionWithDates() {
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(null);

String expectedQuery = String.format("select * from %s where (%s)",
String expectedQuery = String.format("select * from `%s` where (%s)",
TEST_TABLE_SPEC,
TEST_PARTITION_CONDITION);

Expand All @@ -156,7 +156,7 @@ public void testGenerateQuery_TimePartitionWithDates() {
public void testGenerateQuery_TimePartitionRequiredAndFilter() {
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(null);
String expectedQuery = String.format("select * from %s where %s and (%s)",
String expectedQuery = String.format("select * from `%s` where %s and (%s)",
TEST_TABLE_SPEC, TEST_DEFAULT_TIME_CONDITION, TEST_FILTER);

String generatedQuery = format.generateQuery(null, null,
Expand All @@ -175,7 +175,7 @@ public void testGenerateQuery_TimeUnitPartitionWithDates() {
when(mockFieldList.get(TEST_TIME_UNIT_COL)).thenReturn(mockField);
when(mockField.getType()).thenReturn(LegacySQLTypeName.DATE);

String expectedQuery = String.format("select * from %s where (%s)",
String expectedQuery = String.format("select * from `%s` where (%s)",
TEST_TABLE_SPEC, TEST_TIME_UNIT_PARTITION_CONDITION);

String generatedQuery = format.generateQuery(TEST_FROM_DATE, TEST_TO_DATE, null,
Expand All @@ -190,7 +190,7 @@ public void testGenerateQuery_TimePartitionFilterNotRequiredWithDates() {
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(null);

String expectedQuery = String.format("select * from %s where (%s)",
String expectedQuery = String.format("select * from `%s` where (%s)",
TEST_TABLE_SPEC,
TEST_PARTITION_CONDITION);

Expand All @@ -212,7 +212,7 @@ public void testGenerateQuery_NoOptions_ShouldReturnNull() {

@Test
public void testGenerateQuery_WithLimitOnly_ShouldAssertQuery() {
String expectedQuery = String.format("select * from %s limit %s", TEST_TABLE_SPEC,
String expectedQuery = String.format("select * from `%s` limit %s", TEST_TABLE_SPEC,
TEST_LIMIT);

String generatedQuery = format.generateQuery(null, null,
Expand All @@ -224,7 +224,7 @@ public void testGenerateQuery_WithLimitOnly_ShouldAssertQuery() {

@Test
public void testGenerateQuery_WithOrderByOnly_ShouldAssertQuery() {
String expectedQuery = String.format("select * from %s order by %s", TEST_TABLE_SPEC,
String expectedQuery = String.format("select * from `%s` order by %s", TEST_TABLE_SPEC,
TEST_ORDER_BY);

String generatedQuery = format.generateQuery(null, null,
Expand All @@ -239,7 +239,7 @@ public void testGenerateQuery_TimePartitionNotRequired_WithDates_ShouldAssertQue
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(null);

String expectedQuery = String.format("select * from %s where (%s)",
String expectedQuery = String.format("select * from `%s` where (%s)",
TEST_TABLE_SPEC,
TEST_PARTITION_CONDITION);

Expand All @@ -255,7 +255,7 @@ public void testGenerateQuery_TimePartitionRequired_WithFilterOnly_ShouldAssertQ
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(null);

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

String generatedQuery = format.generateQuery(null, null,
Expand All @@ -270,7 +270,7 @@ public void testGenerateQuery_RangePartitionRequiredAndFilter() {
when(mockTableDefinition.getRangePartitioning()).thenReturn(mockRangePartitioning);
when(mockRangePartitioning.getField()).thenReturn("range_col");

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

String generatedQuery = format.generateQuery(null, null, TEST_FILTER,
Expand All @@ -285,7 +285,7 @@ public void testGenerateQuery_RangePartitionRequiredWithLimit() {
when(mockTableDefinition.getRangePartitioning()).thenReturn(mockRangePartitioning);
when(mockRangePartitioning.getField()).thenReturn("range_col");

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

String generatedQuery = format.generateQuery(null, null, null,
Expand All @@ -300,7 +300,7 @@ public void testGenerateQuery_TimeUnitPartitionRequiredAndFilter() {
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(TEST_TIME_UNIT_COL);

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

String generatedQuery = format.generateQuery(null, null, TEST_FILTER,
Expand All @@ -315,7 +315,7 @@ public void testGenerateQuery_TimeUnitPartitionRequiredWithLimit() {
when(mockTableDefinition.getTimePartitioning()).thenReturn(mockTimePartitioning);
when(mockTimePartitioning.getField()).thenReturn(TEST_TIME_UNIT_COL);

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

String generatedQuery = format.generateQuery(null, null, null,
Expand Down
Loading