Skip to content

Commit

Permalink
* #401: Fixed review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaSergienko committed Nov 9, 2020
1 parent 741887d commit 5a157a9
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://docs.aws.amazon.com/athena/latest/ug/select.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void validateProperties() throws PropertyValidationException {
}

@Override
// https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical
public String getStringLiteral(final String value) {
if (value == null) {
return "NULL";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public StructureElementSupport supportsJdbcSchemas() {
}

@Override
// https://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/sqlref/src/tpc/db2z_sqlidentifiers.html
// https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000720.html
public String applyQuote(final String identifier) {
return super.quoteIdentifierWithDoubleQuotes(identifier);
}
Expand All @@ -125,6 +125,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0008470.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://docs.cloudera.com/documentation/enterprise/5-9-x/topics/impala_literals.html#string_literals
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
if (value == null) {
return "NULL";
} else {
return "'" + value.replace("\\", "\\\\").replace("'", "\\'") + "'";
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements003.htm
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://www.postgresql.org/docs/9.2/sql-syntax-lexical.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://docs.aws.amazon.com/redshift/latest/dg/r_Examples_with_character_types.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.04/en-US/885b059cc20340979c8927c9301ceb63.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://docs.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql?view=sql-server-ver15
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01031.0400/doc/html/asc1252677176370.html
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public NullSorting getDefaultNullSorting() {
}

@Override
// https://docs.teradata.com/reader/S0Fw2AVH8ff3MDA0wDOHlQ/74_UPfEbj2v5Yfny_Go8ig
public String getStringLiteral(final String value) {
return super.quoteLiteralStringWithSingleQuote(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.exasol.adapter.dialects.SqlDialect;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

class HiveSqlDialectTest {
private SqlDialect dialect;
Expand Down Expand Up @@ -64,7 +65,7 @@ void testGetCapabilities() {

@Test
void testValidateCatalogProperty() throws PropertyValidationException {
setMandatoryProperties("HIVE");
setMandatoryProperties();
this.rawProperties.put(CATALOG_NAME_PROPERTY, "MY_CATALOG");
final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
final SqlDialect sqlDialect = new HiveSqlDialect(null, adapterProperties);
Expand All @@ -73,7 +74,7 @@ void testValidateCatalogProperty() throws PropertyValidationException {

@Test
void testValidateSchemaProperty() throws PropertyValidationException {
setMandatoryProperties("HIVE");
setMandatoryProperties();
this.rawProperties.put(SCHEMA_NAME_PROPERTY, "MY_SCHEMA");
final AdapterProperties adapterProperties = new AdapterProperties(this.rawProperties);
final SqlDialect sqlDialect = new HiveSqlDialect(null, adapterProperties);
Expand All @@ -88,8 +89,16 @@ void testApplyQuote(final String unquoted, final String quoted) {
assertThat(this.dialect.applyQuote(unquoted), equalTo(quoted));
}

private void setMandatoryProperties(final String sqlDialectProperty) {
this.rawProperties.put(AdapterProperties.SQL_DIALECT_PROPERTY, sqlDialectProperty);
@ValueSource(strings = { "ab:'ab'", "a'b:'a\\'b'", "a''b:'a\\'\\'b'", "'ab':'\\'ab\\''", "a\\b:'a\\\\b'",
"a\\\\b:'a\\\\\\\\b'", "a\\'b:'a\\\\\\'b'" })
@ParameterizedTest
void testGetLiteralString(final String definition) {
assertThat(this.dialect.getStringLiteral(definition.substring(0, definition.indexOf(':'))),
equalTo(definition.substring(definition.indexOf(':') + 1)));
}

private void setMandatoryProperties() {
this.rawProperties.put(AdapterProperties.SQL_DIALECT_PROPERTY, "HIVE");
this.rawProperties.put(AdapterProperties.CONNECTION_NAME_PROPERTY, "MY_CONN");
}
}

0 comments on commit 5a157a9

Please sign in to comment.