Error from Snowflake dll when executing PUT with forward slashes - snowflake-cloud-data-platform

I understand the PUT command requires a file path to copy a file to a staging area. For what I'm doing,
I need to wrap the file path in quotation marks. According to the Snowflake documentation, it is required that the file path use forward slashes (/) instead of the windows-style backslashes () in the file path (for example, if you are trying to PUT the file C:\Documents\file.csv you would have to convert the file path to C:/Documents/file.csv). When I try to execute the PUT command with the forward slashes in the file path, quoted, I get an error from the SnowflakeODBC_sb64_dll. Example: ‘C:/Documents/file.csv’. The error I receive is: “An invalid parameter was passed to a function that considers invalid parameters fatal”. If I convert the file path back to backslashes it appears to work fine. Is this a known issue with the Snowflake driver?
I am doing this on Windows, using native Snowflake driver Version 2.20.1

For windows you can use the (//) with PUT Statement.
Check the below Doc:
https://docs.snowflake.com/en/user-guide/data-load-local-file-system-stage.html#staging-the-data-files3

Related

Use CreateProcess to run bat with spaces

The CreateProcess documentation states that in order to run batch file one has to use cmd.exe /C <path to bat>. In fact it can run batch files just fine unless path to a script contains spaces (Microsoft confirms that in the description of the MS14-019 vulnerability). I wonder if it's possible to escape spaces in the path to batch file to make CreateProcess work. Adding quotes doesn't help, CreateProcess fails with the error:
cannot spawn "<path to batch>": No such file or directory
Update
A workaround is to use short file names as pointed by #jac in the comments. I still wonder why enclosing a path in double quotes works for normal executables but doesn't work for batch files.
There is no escape character for CreateProcess.
Since the code is broken and you can't fix it, you'll have to work around the problem. For example, create a junction point to the target directory and launch the batch file via the junction point path, or use short paths as jac suggested. (Do note that not all volumes will necessarily have short paths enabled, but if you are dealing with the system volume it is probably safe to assume that they will be.)

UNIX Shell script: file reading issue

I have to read a file in my shell script. I was using PL/SQL's UTL_FILE to open the file.
But I have to do a new change which will append timestamp to the file.
e.g import.data file becomes import_20152005101200.data
Now timestamp is the time at which file arrive at the server.
Since the file name changed I can't use the old way of file accessing.
I came up with below solution:
UTL_FILE.FOPEN ('path','import_${file_date}.data','r');
To achieve this I have to get filename and trim it using SUBSTR to get timestamp and pass to file_date variable.
However I am not able to find how to access filename in a particular path. I can use basename. But My file name keeps changing because of timestamp.
Any help/ alternate ideas are welcome.
PL/SQL isn't a good tool to solve this problem; UTL_FILE doesn't have any tools to list all the files in a folder.
A better solution is to define a stored procedure which uses UTL_FILE and pass the file name to process as an argument to the procedure. That way, you use the shell (which has many powerful commands and tools to examine folders and files) or a script language like Python to determine which file to process.

Why doesn't my SSIS File System Task recognize my destination path?

I've set up a File System path inside a ForEachFile enumerator in SSIS 2012. I'm iterating over a directory, loading each file, archiving that file, then processing the next file, etc. I've set the Destination folder via an expression that uses a Project Param value, and I get the source file from the variable set in the ForEachFile enumerator. The File System task says it can't find my Destination folder:
Here's the File System Task:
And proof that the destination folder exists:
Why am I getting this error? I'd swear I've used the exact same technique in SSIS 2008 and 2005. This is 2012, but it should work the same way.
I met the same problem and to resolve it i create a variable and i put something like this in the path.Be carefull you must put double "\ \".
So the path must be like this:"\ \ \ \ad1hfdalhp001\ \d$\ \data\ \Archive\ \"
The DestinationConnection field must contain a reference to a flat file connection. The error is saying that you have no Flat file connection manager with that name.
DestinationConnection should not be a free text field. You should be able to open a drop down in the DestinationConnection field and select or create a connection manager.
You will need to configure your output file path as the ConnectionString property on the file connection manager referenced in the DestinationConnection field.
Using a UNC is still an option. Similar to as you've done with the Source, on your Destination, set IsDestinationPathVariable = True and then push \server\path into a Variable User::ArchivePath or similar.
Otherwise, it is as user3922917 indicates: if IsDestinationPathVariable is false, then you need to use a File Connection manager.
In your comments, you indicate that you're building the UNC path based on an Expression in the File System Task. I find I have a better experience when I build my expressions in SSIS Variables and then simply assign that Variable into the Task's Expression. While this step may seem to provide another layer of maintenance, put a break point on the Task and tell me what the expression evaluates to. And you can't. It's only available to the object to use and you are unable to inspect it so you're left high and dry if your formula is off. Which never happens when you're having to deal with escaping a UNC path

My batch script is reporting an error stating "was unexpected at this time"

The Windows batch file I am trying to run contains the following assignment:
set ANT_HOME="C:/Program Files/apache-ant-1.8.4"
The offending line is:
call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
And when I run the script with echo on I get:
call "C:/Program_Files/apache-ant-1.8.4"/bin/ant -f ../config/common.xml start_db
Files/apache-ant-1.8.4""=="" was unexpected at this time.
I've moved the second quote to to the end of the path, after the ant, but I receive the same error message.
If ant were an .exe I would say your code should work. But I suspect that ant is a batch file, and the error is occurring within the ant script.
I base my conclusion on your error message - specifically the following portion of it: ""=="". The error message is a batch parsing error, and I don't see how your code could generate those characters. So I figure ant must be a batch script that is causing the problem.
I suspect ant.bat has #echo off at the top, so you are not seeing the actual line that is failing.
Not having access to the ant.bat script, I couldn't possibly diagnose exactly what is failing, nor can I guess on how to fix it.
Update - exact problem found
I found a copy of ant.bat online.
It has the following line of code within:
if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME%
Your definition of ANT_HOME includes enclosing quotes, so the code is trying to execute
if ""C:/Program Files/apache-ant-1.8.4""=="" set ANT_HOME=%DEFAULT_ANT_HOME%
The space is not quoted, and you have your error.
All you need to do to fix everything is to remove the quotes from the definition of ANT_HOME, and then add quotes to your CALL statement:
set "ANT_HOME=C:/Program Files/apache-ant-1.8.4"
call "%ANT_HOME%/bin/ant" -f ../config/common.xml start_db
Forward-slashes are not always reliable as folder delimiters within Windows. See Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?.
Better to use back-slashes.
set "ANT_HOME=C:\Program Files\apache-ant-1.8.4"
call "%ANT_HOME%\bin\ant" -f ..\config\common.xml start_db
The quotes have to completely surround a file name. You can't use them for partial names. Try this instead:
set ANT_HOME=C:\Program Files\apache-ant-1.8.4
call "%ANT_HOME%\bin\ant" -f ../config/common.xml start_db
Oh, and I changed some of your slashes to backslashes (DOS doesn't like forward slashes). I assume you are allowed to use / in that parameter you are passing though.

How to convert from DOS path to file scheme URI in Batch file

I'm trying to write a batch file for svnsync, which needs urls to svn repositories. The rest of the batch file uses %~dp0 to get the path of the batch file, but that doesn't work with svnsync.
What is the best way to convert a path (say %~dp0repo, which gets expanded to c:\backup\repo) to a uri suitable for svnsync (file:///c:/backup/repo)?
Ideally it would be able to handle spaces and what not in the path too, so I'd prefer avoid having to use some explicit character replacement to convert from path to URL -- but if that's the only way, oh well.
Thanks!
From your recipe is seems you only need to:
Replace \ with /
Stick file:/// on the front
Here we go:
set DOSPATH=%~dp0repo
set URI=file:///%DOSPATH:\=/%

Resources