Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to upload files to named stages using spaces or special characters #2021

Open
TAGC opened this issue Jan 8, 2025 · 1 comment
Open
Assignees
Labels
bug status-triage Issue is under initial triage

Comments

@TAGC
Copy link

TAGC commented Jan 8, 2025

This issue pertains to a possible bug in the implementation of SnowflakeConnectionV1.uploadStreamInternal. It seems that this method may not be appropriately wrapping the identifier for a named stage in single quotes when it contains spaces or special characters, as is required according to the Snowflake documentation:

Note
If the stage name or path includes spaces or special characters, enclose it in single quotes. For example, use '@"my stage"' for a stage named "my stage".

If you have time, I'd appreciate if this could be confirmed as a bug, or if we're not utilising the method correctly on our end.

Details are included below.


1. What version of JDBC driver are you using?

v3.20.0

2. What operating system and processor architecture are you using?

macOS M1 Pro

3. What version of Java are you using?

Java 17

4. What did you do?

In one of our applications, we utilise SnowflakeConnectionV1 via the following method:

  public void uploadToInternalStage(
      String stageName, String path, InputStream data, String fileName) throws SQLException {
    connection
        .unwrap(SnowflakeConnection.class)
        .uploadStream(stageName, path, data, fileName, false);
  }

We have the following named stages defined within a Snowflake database DATABASE_1 under schema PUBLIC:

  • df_stage_name_lowercase
  • df_STAGE_NAme_with_MIXEd_CASing
  • df stage name with spaces
  • df_stage_name_with_~???@_special_characters

We fully-qualify the stage name we pass to SnowflakeConnectionV1.uploadStream and quote each part of the identifier, e.g. "DATABASE_1"."PUBLIC"."df_stage_name_lowercase".

For the first two test cases, the files are successfully loaded to the named stage. However, for the named stages containing spaces or special characters, the SQL statement used to upload the files fails to execute. For the test case df stage name with spaces, we get the following exception logs:

25-01-08 16:33:44 agent-1  | Caused by: net.snowflake.client.jdbc.SnowflakeSQLException: SQL compilation error:
2025-01-08 16:33:44 agent-1  | syntax error line 1 at position 61 unexpected 'name'.
2025-01-08 16:33:44 agent-1  | syntax error line 1 at position 66 unexpected 'with'.
2025-01-08 16:33:44 agent-1  | parse error line 1 at position 131 near '<EOF>'.

The root cause appears to be that SnowflakeConnectionV1.uploadStreamInternal does not wrap the entire identifier in single quotes when spaces or special characters are present. For this test case, the following SQL statement gets constructed:

put file:///tmp/placeholder @"DATABASE_1"."PUBLIC"."df stage name with spaces"/d6cf4234-2f17-40cb-a2c0-b68a729b16ad/ overwrite=true

Based on the Snowflake docs referenced above, I believe it ought to be:

put file:///tmp/placeholder '@"DATABASE_1"."PUBLIC"."df stage name with spaces"'/d6cf4234-2f17-40cb-a2c0-b68a729b16ad/ overwrite=true

5. What did you expect to see?

I expect that the Snowflake connector succeeds in uploading files to named stages regardless of whether there are spaces or special characters in the name.

6. Can you set logging to DEBUG and collect the logs?

I believe the logs included below should be sufficient to debug the issue, but let me know if more logs are required:

2025-01-08 16:33:44 agent-1  | Caused by: net.snowflake.client.jdbc.SnowflakeSQLException: SQL compilation error:
2025-01-08 16:33:44 agent-1  | syntax error line 1 at position 61 unexpected 'name'.
2025-01-08 16:33:44 agent-1  | syntax error line 1 at position 66 unexpected 'with'.
2025-01-08 16:33:44 agent-1  | parse error line 1 at position 131 near '<EOF>'.
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeUtil.checkErrorAndThrowExceptionSub(SnowflakeUtil.java:176)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeUtil.checkErrorAndThrowException(SnowflakeUtil.java:109)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.core.StmtUtil.pollForOutput(StmtUtil.java:490)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.core.StmtUtil.execute(StmtUtil.java:396)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.core.SFStatement.executeHelper(SFStatement.java:498)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeFileTransferAgent.parseCommandInGS(SnowflakeFileTransferAgent.java:1299)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeFileTransferAgent.parseCommand(SnowflakeFileTransferAgent.java:919)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeFileTransferAgent.<init>(SnowflakeFileTransferAgent.java:895)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.DefaultSFConnectionHandler.getFileTransferAgent(DefaultSFConnectionHandler.java:381)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeConnectionV1.uploadStreamInternal(SnowflakeConnectionV1.java:959)
2025-01-08 16:33:44 agent-1  |  at net.snowflake.client.jdbc.SnowflakeConnectionV1.uploadStream(SnowflakeConnectionV1.java:864)
@TAGC TAGC added the bug label Jan 8, 2025
@TAGC TAGC changed the title Named stages using spaces or special characters are not quoted in "PUT file" SQL statements Unable to upload files to named stages using spaces or special characters Jan 8, 2025
@sfc-gh-sghosh sfc-gh-sghosh self-assigned this Jan 10, 2025
@sfc-gh-sghosh sfc-gh-sghosh added the status-triage Issue is under initial triage label Jan 10, 2025
@sfc-gh-sghosh
Copy link
Contributor

Hello @TAGC ,

Thanks for raising the issue, we are looking into it, will update.

Regards,
Sujan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status-triage Issue is under initial triage
Projects
None yet
Development

No branches or pull requests

2 participants