Skip to content

Commit

Permalink
Fix Snowflake temp table creation with BIT columns (#2352)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-gunjan authored Oct 11, 2023
1 parent 3fbd852 commit 17a30ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.finos.legend.engine.plan.execution.stores.relational.connection.driver.vendors.snowflake;

import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.ImmutableMap;
import org.finos.legend.engine.plan.execution.stores.relational.connection.driver.commands.Column;
import org.finos.legend.engine.plan.execution.stores.relational.connection.driver.commands.IngestionMethod;
import org.finos.legend.engine.plan.execution.stores.relational.connection.driver.commands.RelationalDatabaseCommands;
Expand All @@ -25,6 +27,8 @@

public class SnowflakeCommands extends RelationalDatabaseCommands
{
private static final ImmutableMap<String, String> columnTypeToSqlTextMap = Maps.immutable.of("BIT", "BOOLEAN");

@Override
public String processTempTableName(String tempTableName)
{
Expand All @@ -50,7 +54,7 @@ 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 + " " + columnTypeToSqlTextMap.getIfAbsentValue(c.type, 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= '\"')",
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 17a30ac

Please sign in to comment.