@@ -3210,6 +3210,74 @@ orders PIVOT (sum(amount) FOR status IN ('open'))`
32103210 expect ( result2 . ast [ 0 ] . type ) . toBe ( result1 . ast [ 0 ] . type )
32113211 } )
32123212 }
3213+
3214+ it ( "COPY TO round-trip: PARTITION_BY value is NOT quoted" , ( ) => {
3215+ const sql = "COPY trades TO '/export/trades' WITH PARTITION_BY MONTH"
3216+ const result = parseToAst ( sql )
3217+ expect ( result . errors ) . toHaveLength ( 0 )
3218+
3219+ const roundtrip = toSql ( result . ast [ 0 ] )
3220+ expect ( roundtrip ) . toContain ( "PARTITION_BY MONTH" )
3221+ expect ( roundtrip ) . not . toContain ( "PARTITION_BY 'MONTH'" )
3222+
3223+ const result2 = parseToAst ( roundtrip )
3224+ expect ( result2 . errors ) . toHaveLength ( 0 )
3225+ } )
3226+
3227+ it ( "COPY TO round-trip: FORMAT, PARTITION_BY and COMPRESSION_CODEC are NOT quoted" , ( ) => {
3228+ const sql =
3229+ "COPY trades TO '/export/trades' WITH FORMAT PARQUET " +
3230+ "PARTITION_BY MONTH COMPRESSION_CODEC ZSTD"
3231+ const result = parseToAst ( sql )
3232+ expect ( result . errors ) . toHaveLength ( 0 )
3233+
3234+ const roundtrip = toSql ( result . ast [ 0 ] )
3235+ expect ( roundtrip ) . toContain ( "FORMAT PARQUET" )
3236+ expect ( roundtrip ) . toContain ( "PARTITION_BY MONTH" )
3237+ expect ( roundtrip ) . toContain ( "COMPRESSION_CODEC ZSTD" )
3238+
3239+ const result2 = parseToAst ( roundtrip )
3240+ expect ( result2 . errors ) . toHaveLength ( 0 )
3241+ } )
3242+
3243+ it ( "COPY TO round-trip: PARQUET_VERSION accepts bare number literal" , ( ) => {
3244+ const sql =
3245+ "COPY trades TO '/export/trades' WITH FORMAT PARQUET PARQUET_VERSION 2"
3246+ const result = parseToAst ( sql )
3247+ expect ( result . errors ) . toHaveLength ( 0 )
3248+
3249+ const roundtrip = toSql ( result . ast [ 0 ] )
3250+ expect ( roundtrip ) . toContain ( "PARQUET_VERSION 2" )
3251+
3252+ const result2 = parseToAst ( roundtrip )
3253+ expect ( result2 . errors ) . toHaveLength ( 0 )
3254+ } )
3255+
3256+ it ( "COPY FROM round-trip: string literal options are still quoted" , ( ) => {
3257+ const sql = "COPY trades FROM '/data/trades.csv' WITH DELIMITER ','"
3258+ const result = parseToAst ( sql )
3259+ expect ( result . errors ) . toHaveLength ( 0 )
3260+
3261+ const roundtrip = toSql ( result . ast [ 0 ] )
3262+ expect ( roundtrip ) . toContain ( "DELIMITER ','" )
3263+
3264+ const result2 = parseToAst ( roundtrip )
3265+ expect ( result2 . errors ) . toHaveLength ( 0 )
3266+ } )
3267+
3268+ it ( "COPY TO with subquery and all Parquet options" , ( ) => {
3269+ const sql =
3270+ "COPY (SELECT * FROM trades WHERE timestamp IN '2024') TO '/export/trades' " +
3271+ "WITH FORMAT PARQUET PARTITION_BY MONTH COMPRESSION_CODEC ZSTD COMPRESSION_LEVEL 3 " +
3272+ "ROW_GROUP_SIZE 100000 DATA_PAGE_SIZE 1048576 STATISTICS_ENABLED true PARQUET_VERSION 2 " +
3273+ "RAW_ARRAY_ENCODING true"
3274+ const result = parseToAst ( sql )
3275+ expect ( result . errors ) . toHaveLength ( 0 )
3276+
3277+ const roundtrip = toSql ( result . ast [ 0 ] )
3278+ const result2 = parseToAst ( roundtrip )
3279+ expect ( result2 . errors ) . toHaveLength ( 0 )
3280+ } )
32133281 } )
32143282
32153283 // ===========================================================================
0 commit comments