使用批处理脚本将 CSV 文件数据加载到雪花云 table
load CSV file data to snowflake cloud table using batch scripting
我是批处理脚本的新手,我的要求是将 CSV 文件复制到 snowfalke table。
我曾尝试使用
copy into command
由 SNOWFLAKE 文档提供。
但不幸的是它不起作用,请帮我解决这些问题。
这是我亲手尝试过的
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set fullstamp=select * from Tbl_Store where OperationDate='%YYYY%-%MM%-%DD%'
set filename=Tbl_Store_%YYYY%_%MM%_%DD%
sqlcmd -S ta -d SMS_Online -U sa -P ***-h -1 -s, -W -Q "%fullstamp%" -s "," -o "E:\Workspace\%filename%.csv"
set File_Name=%filename%.csv
: path to Output the
set File_PATH=E:\Workspace\
: Set Bucket Path
set AWSBUCKET=s3://S3_TEST
: Set AWS path
set AWSPROFILE= S3_TEST
: upload the ZIP FILE to the AWS
:aws s3 cp %File_PATH%%File_Name% %AWSBUCKET%
:Copy into SnowFlake
copy into table_name from %File_PATH%%File_Name%
我使用 snowsql.exe 找到了解决方案,我们需要对其进行配置。
通过批处理,我将 ddl 语句生成到一个文本文件中,然后我使用以下命令执行 SQL 语句以在 Snowflake 上执行数据加载。
copy into tablename from @my_s3_stage/%file_path and name on_error = 'skip_file' force=true;
snowsql -c Schema_Name -f file_path
@my_s3_stage stage need to create on snowfalke IDE
我是批处理脚本的新手,我的要求是将 CSV 文件复制到 snowfalke table。
我曾尝试使用
copy into command
由 SNOWFLAKE 文档提供。
但不幸的是它不起作用,请帮我解决这些问题。
这是我亲手尝试过的
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set fullstamp=select * from Tbl_Store where OperationDate='%YYYY%-%MM%-%DD%'
set filename=Tbl_Store_%YYYY%_%MM%_%DD%
sqlcmd -S ta -d SMS_Online -U sa -P ***-h -1 -s, -W -Q "%fullstamp%" -s "," -o "E:\Workspace\%filename%.csv"
set File_Name=%filename%.csv
: path to Output the
set File_PATH=E:\Workspace\
: Set Bucket Path
set AWSBUCKET=s3://S3_TEST
: Set AWS path
set AWSPROFILE= S3_TEST
: upload the ZIP FILE to the AWS
:aws s3 cp %File_PATH%%File_Name% %AWSBUCKET%
:Copy into SnowFlake
copy into table_name from %File_PATH%%File_Name%
我使用 snowsql.exe 找到了解决方案,我们需要对其进行配置。
通过批处理,我将 ddl 语句生成到一个文本文件中,然后我使用以下命令执行 SQL 语句以在 Snowflake 上执行数据加载。
copy into tablename from @my_s3_stage/%file_path and name on_error = 'skip_file' force=true;
snowsql -c Schema_Name -f file_path
@my_s3_stage stage need to create on snowfalke IDE