Skip to content

Commit

Permalink
fix bug while creating temporary tables in snowflake for bit type
Browse files Browse the repository at this point in the history
fix bug while creating temporary tables for snowflake for bit type
  • Loading branch information
gs-gunjan authored Oct 10, 2023
1 parent cdda855 commit 70eb345
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ public List<String> createAndLoadTempTable(String tableName, List<Column> column
optionalCSVFileLocation = optionalCSVFileLocation.substring(1);
}
List<String> strings = Arrays.asList(
"CREATE TEMPORARY TABLE " + tableName + " " + columns.stream().map(c -> c.name + " " + c.type).collect(Collectors.joining(",", "(", ")")),
"CREATE TEMPORARY TABLE " + tableName + " " + columns.stream().map(c -> c.name + " " + mapColumnTypeToSqlText(c.type)).collect(Collectors.joining(",", "(", ")")),
"CREATE OR REPLACE TEMPORARY STAGE " + tempStageName(),
"PUT file:///" + optionalCSVFileLocation + " @" + tempStageName() + "/" + optionalCSVFileLocation + " PARALLEL = 16 AUTO_COMPRESS = TRUE",
"COPY INTO " + tableName + " FROM @" + tempStageName() + "/" + optionalCSVFileLocation + " file_format = (type = CSV field_optionally_enclosed_by= '\"')",
"DROP STAGE " + tempStageName()
);
return strings;
}

private String mapColumnTypeToSqlText(String columnType)
{
switch (columnType)
{
case "BIT" : return "BOOLEAN";
default: return columnType;
}
}

@Override
public IngestionMethod getDefaultIngestionMethod()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public void testTempTableCommands() throws IOException

ImmutableList<Column> columns = Lists.immutable.of(
new Column("a", "VARCHAR(100)"),
new Column("b", "VARCHAR(100)")
new Column("b", "VARCHAR(100)"),
new Column("c", "BIT")
);

List<String> sqlStatements = snowflakeCommands.createAndLoadTempTable("temp_1", columns.castToList(), "/tmp/temp.csv");
ImmutableList<String> expectedSQLStatements = Lists.immutable.of(
"CREATE TEMPORARY TABLE temp_1 (a VARCHAR(100),b VARCHAR(100))",
"CREATE TEMPORARY TABLE temp_1 (a VARCHAR(100),b VARCHAR(100),c BOOLEAN)",
"CREATE OR REPLACE TEMPORARY STAGE LEGEND_TEMP_DB.LEGEND_TEMP_SCHEMA.LEGEND_TEMP_STAGE",
"PUT file:///tmp/temp.csv @LEGEND_TEMP_DB.LEGEND_TEMP_SCHEMA.LEGEND_TEMP_STAGE/tmp/temp.csv PARALLEL = 16 AUTO_COMPRESS = TRUE",
"COPY INTO temp_1 FROM @LEGEND_TEMP_DB.LEGEND_TEMP_SCHEMA.LEGEND_TEMP_STAGE/tmp/temp.csv file_format = (type = CSV field_optionally_enclosed_by= '\"')",
Expand Down

0 comments on commit 70eb345

Please sign in to comment.