usql icon indicating copy to clipboard operation
usql copied to clipboard

Check if file exists at the location.

Open lokesh-zende opened this issue 8 years ago • 4 comments

Hi, Is there a way to check if the file from which we will be extracting values exists at that location?

IF File.Exists("file_location")
THEN
       //Proceed further, extract values from the file using Extractor.
ELSE
       // Other things to do

lokesh-zende avatar Apr 12 '17 09:04 lokesh-zende

Something like this?

IF (FILE.EXISTS("/Samples/Data/SearchLog.tsv"))
THEN
    @searchlog =
        EXTRACT UserId          int,
                Start           DateTime,
                Region          string,
                Query           string,
                Duration        int?,
                Urls            string,
                ClickedUrls     string
        FROM "/Samples/Data/SearchLog.tsv"
        USING Extractors.Tsv();
ELSE 
    @searchlog = 
        SELECT * FROM 
            ( VALUES
            ("Not Exist")
            ) AS T(col1);
END;

OUTPUT @searchlog   
TO @"/Samples/Data/Test.txt"
USING Outputters.Csv();

dagiro avatar Apr 13 '17 00:04 dagiro

dagiro, I tried the same, but it does not work. It gives compile time error ,"File not found".

lokesh-zende avatar Apr 13 '17 03:04 lokesh-zende

The above should work. Can you provide me with a repro? Also did you try it locally or on a cluster account?

MikeRys avatar Apr 19 '17 19:04 MikeRys

MikeRys, I tried it locally.

lokesh-zende avatar Apr 20 '17 03:04 lokesh-zende