sqlingo 0.8.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +2 -2
- package/README.npm.md +2 -2
- package/README.repo.md +2 -2
- package/dist/chunk-253CRNX3.cjs +2 -0
- package/dist/chunk-253CRNX3.cjs.map +1 -0
- package/dist/chunk-3XSLMNQQ.js +19 -0
- package/dist/chunk-3XSLMNQQ.js.map +1 -0
- package/dist/chunk-45T22NWK.cjs +2 -0
- package/dist/chunk-45T22NWK.cjs.map +1 -0
- package/dist/chunk-5GVA4XPZ.cjs +2 -0
- package/dist/{chunk-HQEUEZZE.cjs.map → chunk-5GVA4XPZ.cjs.map} +1 -1
- package/dist/chunk-6T7XKWKA.js +2 -0
- package/dist/chunk-6T7XKWKA.js.map +1 -0
- package/dist/{chunk-457OPBHX.js → chunk-7UEXD3RC.js} +2 -2
- package/dist/chunk-7XPPJ275.cjs +2 -0
- package/dist/{chunk-QEXGYHWM.cjs.map → chunk-7XPPJ275.cjs.map} +1 -1
- package/dist/chunk-CTSGJUVV.cjs +2 -0
- package/dist/{chunk-OOA5D6BW.cjs.map → chunk-CTSGJUVV.cjs.map} +1 -1
- package/dist/chunk-DOCVJID4.js +2 -0
- package/dist/{chunk-NMAMNFRD.js.map → chunk-DOCVJID4.js.map} +1 -1
- package/dist/{chunk-KZSNUA4U.js → chunk-EBXKDF3U.js} +2 -2
- package/dist/chunk-EBXKDF3U.js.map +1 -0
- package/dist/{chunk-3OVM5ZRR.js → chunk-EO7P6GX2.js} +2 -2
- package/dist/{chunk-GFWBSTYA.js → chunk-FDZGJ5M3.js} +2 -2
- package/dist/chunk-GQS7NEWT.cjs +2 -0
- package/dist/{chunk-O4K6VGOH.cjs.map → chunk-GQS7NEWT.cjs.map} +1 -1
- package/dist/{chunk-QWCG55SR.js → chunk-GYC3WNMF.js} +2 -2
- package/dist/chunk-HF3BBINH.cjs +19 -0
- package/dist/chunk-HF3BBINH.cjs.map +1 -0
- package/dist/{chunk-5JXGMU6K.js → chunk-HN25JG4E.js} +2 -2
- package/dist/chunk-HVGOPPO6.cjs +2 -0
- package/dist/{chunk-USYIWEPI.cjs.map → chunk-HVGOPPO6.cjs.map} +1 -1
- package/dist/{chunk-PGKNO72J.js → chunk-II6KO4YM.js} +2 -2
- package/dist/chunk-IZ6FO5XV.cjs +4 -0
- package/dist/{chunk-UMJ6E4XD.cjs.map → chunk-IZ6FO5XV.cjs.map} +1 -1
- package/dist/chunk-J3WE7VU2.cjs +2 -0
- package/dist/{chunk-LDIWFKFA.cjs.map → chunk-J3WE7VU2.cjs.map} +1 -1
- package/dist/{chunk-NKPY5IG3.js → chunk-NKTCFXES.js} +2 -2
- package/dist/chunk-NLMQEXP6.js +2 -0
- package/dist/chunk-NLMQEXP6.js.map +1 -0
- package/dist/chunk-OTPFZMI5.cjs +2 -0
- package/dist/{chunk-OGPS63WZ.cjs.map → chunk-OTPFZMI5.cjs.map} +1 -1
- package/dist/{chunk-DW3ISHFW.js → chunk-P4L2DZSO.js} +2 -2
- package/dist/chunk-P4L2DZSO.js.map +1 -0
- package/dist/{chunk-WRG5B5DZ.js → chunk-Q6ZJFJGH.js} +2 -2
- package/dist/{chunk-WRG5B5DZ.js.map → chunk-Q6ZJFJGH.js.map} +1 -1
- package/dist/{chunk-KNRQDMQ7.js → chunk-QON2LPKU.js} +2 -2
- package/dist/chunk-SGMSSLF5.cjs +2 -0
- package/dist/{chunk-PVJGPE3V.cjs.map → chunk-SGMSSLF5.cjs.map} +1 -1
- package/dist/{chunk-NBRX75ID.js → chunk-TP2BCA77.js} +2 -2
- package/dist/{chunk-SPWMHIMC.js → chunk-TQ6CASZR.js} +2 -2
- package/dist/chunk-UZ6MAXLW.cjs +2 -0
- package/dist/{chunk-Y2ZD6UO6.cjs.map → chunk-UZ6MAXLW.cjs.map} +1 -1
- package/dist/{chunk-DGV6NM76.js → chunk-VNTZ5D4A.js} +2 -2
- package/dist/{chunk-DGV6NM76.js.map → chunk-VNTZ5D4A.js.map} +1 -1
- package/dist/chunk-VV4LMUMT.cjs +2 -0
- package/dist/{chunk-47UFIVIO.cjs.map → chunk-VV4LMUMT.cjs.map} +1 -1
- package/dist/chunk-WDQMMMTX.cjs +2 -0
- package/dist/{chunk-I36ZOBUW.cjs.map → chunk-WDQMMMTX.cjs.map} +1 -1
- package/dist/{chunk-FYYDDWAY.cjs → chunk-YUVN3ZOA.cjs} +2 -2
- package/dist/{chunk-FYYDDWAY.cjs.map → chunk-YUVN3ZOA.cjs.map} +1 -1
- package/dist/{chunk-AKDNSOG6.js → chunk-YXHFRUY4.js} +2 -2
- package/dist/chunk-Z6NSUNEB.cjs +2 -0
- package/dist/{chunk-KYKSQHLH.cjs.map → chunk-Z6NSUNEB.cjs.map} +1 -1
- package/dist/chunk-ZNCQ6OPU.cjs +3 -0
- package/dist/chunk-ZNCQ6OPU.cjs.map +1 -0
- package/dist/chunk-ZTQHO742.cjs +2 -0
- package/dist/{chunk-6EWE2PXX.cjs.map → chunk-ZTQHO742.cjs.map} +1 -1
- package/dist/dialects/athena.cjs +1 -1
- package/dist/dialects/athena.d.cts +1 -1
- package/dist/dialects/athena.d.ts +1 -1
- package/dist/dialects/athena.js +1 -1
- package/dist/dialects/bigquery.cjs +2 -2
- package/dist/dialects/bigquery.cjs.map +1 -1
- package/dist/dialects/bigquery.d.cts +4 -2
- package/dist/dialects/bigquery.d.ts +4 -2
- package/dist/dialects/bigquery.js +2 -2
- package/dist/dialects/bigquery.js.map +1 -1
- package/dist/dialects/clickhouse.cjs +1 -1
- package/dist/dialects/clickhouse.cjs.map +1 -1
- package/dist/dialects/clickhouse.d.cts +3 -1
- package/dist/dialects/clickhouse.d.ts +3 -1
- package/dist/dialects/clickhouse.js +1 -1
- package/dist/dialects/clickhouse.js.map +1 -1
- package/dist/dialects/databricks.cjs +1 -1
- package/dist/dialects/databricks.cjs.map +1 -1
- package/dist/dialects/databricks.d.cts +2 -1
- package/dist/dialects/databricks.d.ts +2 -1
- package/dist/dialects/databricks.js +1 -1
- package/dist/dialects/databricks.js.map +1 -1
- package/dist/dialects/doris.cjs +1 -1
- package/dist/dialects/doris.d.cts +2 -1
- package/dist/dialects/doris.d.ts +2 -1
- package/dist/dialects/doris.js +1 -1
- package/dist/dialects/dremio.cjs +1 -1
- package/dist/dialects/dremio.cjs.map +1 -1
- package/dist/dialects/dremio.d.cts +2 -1
- package/dist/dialects/dremio.d.ts +2 -1
- package/dist/dialects/dremio.js +1 -1
- package/dist/dialects/dremio.js.map +1 -1
- package/dist/dialects/drill.cjs +1 -1
- package/dist/dialects/drill.d.cts +2 -1
- package/dist/dialects/drill.d.ts +2 -1
- package/dist/dialects/drill.js +1 -1
- package/dist/dialects/druid.cjs +1 -1
- package/dist/dialects/druid.d.cts +1 -1
- package/dist/dialects/druid.d.ts +1 -1
- package/dist/dialects/druid.js +1 -1
- package/dist/dialects/duckdb.cjs +22 -13
- package/dist/dialects/duckdb.cjs.map +1 -1
- package/dist/dialects/duckdb.d.cts +9 -2
- package/dist/dialects/duckdb.d.ts +9 -2
- package/dist/dialects/duckdb.js +14 -5
- package/dist/dialects/duckdb.js.map +1 -1
- package/dist/dialects/dune.cjs +1 -1
- package/dist/dialects/dune.d.cts +1 -1
- package/dist/dialects/dune.d.ts +1 -1
- package/dist/dialects/dune.js +1 -1
- package/dist/dialects/exasol.cjs +1 -1
- package/dist/dialects/exasol.d.cts +2 -1
- package/dist/dialects/exasol.d.ts +2 -1
- package/dist/dialects/exasol.js +1 -1
- package/dist/dialects/fabric.cjs +1 -1
- package/dist/dialects/fabric.d.cts +2 -1
- package/dist/dialects/fabric.d.ts +2 -1
- package/dist/dialects/fabric.js +1 -1
- package/dist/dialects/hive.cjs +1 -1
- package/dist/dialects/hive.d.cts +3 -2
- package/dist/dialects/hive.d.ts +3 -2
- package/dist/dialects/hive.js +1 -1
- package/dist/dialects/materialize.cjs +1 -1
- package/dist/dialects/materialize.cjs.map +1 -1
- package/dist/dialects/materialize.d.cts +4 -1
- package/dist/dialects/materialize.d.ts +4 -1
- package/dist/dialects/materialize.js +1 -1
- package/dist/dialects/materialize.js.map +1 -1
- package/dist/dialects/mysql.cjs +1 -1
- package/dist/dialects/mysql.d.cts +2 -2
- package/dist/dialects/mysql.d.ts +2 -2
- package/dist/dialects/mysql.js +1 -1
- package/dist/dialects/oracle.cjs +1 -1
- package/dist/dialects/oracle.d.cts +2 -1
- package/dist/dialects/oracle.d.ts +2 -1
- package/dist/dialects/oracle.js +1 -1
- package/dist/dialects/postgres.cjs +1 -1
- package/dist/dialects/postgres.d.cts +2 -1
- package/dist/dialects/postgres.d.ts +2 -1
- package/dist/dialects/postgres.js +1 -1
- package/dist/dialects/presto.cjs +1 -1
- package/dist/dialects/presto.d.cts +1 -1
- package/dist/dialects/presto.d.ts +1 -1
- package/dist/dialects/presto.js +1 -1
- package/dist/dialects/prql.cjs +1 -1
- package/dist/dialects/prql.cjs.map +1 -1
- package/dist/dialects/prql.d.cts +2 -1
- package/dist/dialects/prql.d.ts +2 -1
- package/dist/dialects/prql.js +1 -1
- package/dist/dialects/prql.js.map +1 -1
- package/dist/dialects/redshift.cjs +1 -1
- package/dist/dialects/redshift.cjs.map +1 -1
- package/dist/dialects/redshift.d.cts +1 -1
- package/dist/dialects/redshift.d.ts +1 -1
- package/dist/dialects/redshift.js +1 -1
- package/dist/dialects/redshift.js.map +1 -1
- package/dist/dialects/risingwave.cjs +1 -1
- package/dist/dialects/risingwave.d.cts +2 -1
- package/dist/dialects/risingwave.d.ts +2 -1
- package/dist/dialects/risingwave.js +1 -1
- package/dist/dialects/singlestore.cjs +1 -1
- package/dist/dialects/singlestore.d.cts +1 -1
- package/dist/dialects/singlestore.d.ts +1 -1
- package/dist/dialects/singlestore.js +1 -1
- package/dist/dialects/snowflake.cjs +2 -2
- package/dist/dialects/snowflake.cjs.map +1 -1
- package/dist/dialects/snowflake.d.cts +19 -13
- package/dist/dialects/snowflake.d.ts +19 -13
- package/dist/dialects/snowflake.js +2 -2
- package/dist/dialects/snowflake.js.map +1 -1
- package/dist/dialects/solr.cjs +1 -1
- package/dist/dialects/solr.d.cts +2 -1
- package/dist/dialects/solr.d.ts +2 -1
- package/dist/dialects/solr.js +1 -1
- package/dist/dialects/spark.cjs +1 -1
- package/dist/dialects/spark.d.cts +2 -1
- package/dist/dialects/spark.d.ts +2 -1
- package/dist/dialects/spark.js +1 -1
- package/dist/dialects/spark2.cjs +1 -1
- package/dist/dialects/spark2.d.cts +2 -1
- package/dist/dialects/spark2.d.ts +2 -1
- package/dist/dialects/spark2.js +1 -1
- package/dist/dialects/sqlite.cjs +1 -1
- package/dist/dialects/sqlite.d.cts +2 -1
- package/dist/dialects/sqlite.d.ts +2 -1
- package/dist/dialects/sqlite.js +1 -1
- package/dist/dialects/starrocks.cjs +1 -1
- package/dist/dialects/starrocks.d.cts +2 -1
- package/dist/dialects/starrocks.d.ts +2 -1
- package/dist/dialects/starrocks.js +1 -1
- package/dist/dialects/tableau.cjs +1 -1
- package/dist/dialects/tableau.d.cts +2 -1
- package/dist/dialects/tableau.d.ts +2 -1
- package/dist/dialects/tableau.js +1 -1
- package/dist/dialects/teradata.cjs +1 -1
- package/dist/dialects/teradata.cjs.map +1 -1
- package/dist/dialects/teradata.d.cts +2 -4
- package/dist/dialects/teradata.d.ts +2 -4
- package/dist/dialects/teradata.js +1 -1
- package/dist/dialects/teradata.js.map +1 -1
- package/dist/dialects/trino.cjs +1 -1
- package/dist/dialects/trino.d.cts +2 -1
- package/dist/dialects/trino.d.ts +2 -1
- package/dist/dialects/trino.js +1 -1
- package/dist/dialects/tsql.cjs +1 -1
- package/dist/dialects/tsql.d.cts +3 -2
- package/dist/dialects/tsql.d.ts +3 -2
- package/dist/dialects/tsql.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{tokens-DOFGCO-T.d.ts → tokens-qxb1e_iq.d.cts} +56 -6
- package/dist/{tokens-DOFGCO-T.d.cts → tokens-qxb1e_iq.d.ts} +56 -6
- package/package.json +6 -4
- package/dist/chunk-47UFIVIO.cjs +0 -2
- package/dist/chunk-5E2DDDMJ.cjs +0 -2
- package/dist/chunk-5E2DDDMJ.cjs.map +0 -1
- package/dist/chunk-6EWE2PXX.cjs +0 -2
- package/dist/chunk-AYV6C6YU.cjs +0 -19
- package/dist/chunk-AYV6C6YU.cjs.map +0 -1
- package/dist/chunk-C4ZR72YB.cjs +0 -3
- package/dist/chunk-C4ZR72YB.cjs.map +0 -1
- package/dist/chunk-DW3ISHFW.js.map +0 -1
- package/dist/chunk-FCFBBB5S.cjs +0 -2
- package/dist/chunk-FCFBBB5S.cjs.map +0 -1
- package/dist/chunk-HQEUEZZE.cjs +0 -2
- package/dist/chunk-I36ZOBUW.cjs +0 -2
- package/dist/chunk-KYKSQHLH.cjs +0 -2
- package/dist/chunk-KZSNUA4U.js.map +0 -1
- package/dist/chunk-LDIWFKFA.cjs +0 -2
- package/dist/chunk-NMAMNFRD.js +0 -2
- package/dist/chunk-O4K6VGOH.cjs +0 -2
- package/dist/chunk-OGPS63WZ.cjs +0 -2
- package/dist/chunk-OOA5D6BW.cjs +0 -2
- package/dist/chunk-PC37XGLS.js +0 -2
- package/dist/chunk-PC37XGLS.js.map +0 -1
- package/dist/chunk-PVJGPE3V.cjs +0 -2
- package/dist/chunk-QEXGYHWM.cjs +0 -2
- package/dist/chunk-R2XOYY2B.js +0 -2
- package/dist/chunk-R2XOYY2B.js.map +0 -1
- package/dist/chunk-RGKTYIN3.js +0 -19
- package/dist/chunk-RGKTYIN3.js.map +0 -1
- package/dist/chunk-UMJ6E4XD.cjs +0 -4
- package/dist/chunk-USYIWEPI.cjs +0 -2
- package/dist/chunk-Y2ZD6UO6.cjs +0 -2
- /package/dist/{chunk-457OPBHX.js.map → chunk-7UEXD3RC.js.map} +0 -0
- /package/dist/{chunk-3OVM5ZRR.js.map → chunk-EO7P6GX2.js.map} +0 -0
- /package/dist/{chunk-GFWBSTYA.js.map → chunk-FDZGJ5M3.js.map} +0 -0
- /package/dist/{chunk-QWCG55SR.js.map → chunk-GYC3WNMF.js.map} +0 -0
- /package/dist/{chunk-5JXGMU6K.js.map → chunk-HN25JG4E.js.map} +0 -0
- /package/dist/{chunk-PGKNO72J.js.map → chunk-II6KO4YM.js.map} +0 -0
- /package/dist/{chunk-NKPY5IG3.js.map → chunk-NKTCFXES.js.map} +0 -0
- /package/dist/{chunk-KNRQDMQ7.js.map → chunk-QON2LPKU.js.map} +0 -0
- /package/dist/{chunk-NBRX75ID.js.map → chunk-TP2BCA77.js.map} +0 -0
- /package/dist/{chunk-SPWMHIMC.js.map → chunk-TQ6CASZR.js.map} +0 -0
- /package/dist/{chunk-AKDNSOG6.js.map → chunk-YXHFRUY4.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as Dialect, a as Dialects, a5 as NullOrdering, N as NormalizationStrategy, E as Expression, a8 as TypeAnnotator, i as DataTypeExprKind, d as Tokenizer, e as TokenPair, f as TokenType, g as Parser,
|
|
1
|
+
import { D as Dialect, a as Dialects, a5 as NullOrdering, N as NormalizationStrategy, E as Expression, a8 as TypeAnnotator, i as DataTypeExprKind, d as Tokenizer, e as TokenPair, f as TokenType, g as Parser, aU as ShowExpr, aA as DataTypeExpr, aV as TableSampleExpr, aW as ToMapExpr, aX as MapExpr, aY as AttachExpr, ak as DetachExpr, aZ as InstallExpr, m as CommandExpr, h as Generator, v as PropertiesLocation, a_ as LastValueExpr, a$ as TimeSliceExpr, b0 as BitmapBucketNumberExpr, b1 as BitmapBitPositionExpr, b2 as BitmapConstructAggExpr, b3 as NthValueExpr, b4 as RandstrExpr, b5 as ZipfExpr, b6 as ToBinaryExpr, b7 as GreatestExpr, b8 as LeastExpr, b9 as GeneratorExpr, ba as LambdaExpr, bb as SortArrayExpr, bc as ApproxTopKExpr, bd as FromIso8601TimestampExpr, a0 as StrToTimeExpr, av as StrToDateExpr, be as TsOrDsToTimeExpr, bf as RegexpLikeExpr, bg as ArrayOverlapsExpr, W as ArrayContainsExpr, bh as ArrayUniqueAggExpr, bi as ArrayDistinctExpr, bj as RegexpInstrExpr, bk as RegexpReplaceExpr, bl as RegexpCountExpr, bm as ArrayIntersectExpr, bn as ArrayExceptExpr, aL as CurrentDateExpr, bo as CheckJsonExpr, bp as ParseJsonExpr, bq as TruncExpr, br as NormalExpr, aO as UniformExpr, bs as TimeFromPartsExpr, aa as ExtractExpr, bt as TimestampFromPartsExpr, bu as TimestampLtzFromPartsExpr, bv as TimestampTzFromPartsExpr, aM as ColumnDefExpr, ag as JoinExpr, O as GenerateSeriesExpr, bw as CountIfExpr, I as BracketExpr, bx as WithinGroupExpr, by as LengthExpr, $ as LevenshteinExpr, bz as PadExpr, bA as MinhashExpr, bB as MinhashCombineExpr, bC as ApproximateSimilarityExpr, bD as ArraySliceExpr, bE as ArraysZipExpr, bF as LowerExpr, bG as UpperExpr, bH as ReverseExpr, bI as RandExpr, bJ as RightExpr, bK as Base64EncodeExpr, bL as ReplaceExpr, bM as BinaryExpr, bN as BitwiseXorExpr, bO as ObjectInsertExpr, bP as MapCatExpr, bQ as MapDeleteExpr, bR as MapSizeExpr, bS as MapPickExpr, bT as MapInsertExpr, bU as StartsWithExpr, bV as SpaceExpr, bW as TableFromRowsExpr, U as UnnestExpr, bX as IgnoreNullsExpr, bY as SplitExpr, bZ as SplitPartExpr, b_ as RespectNullsExpr, b$ as ArrayToStringExpr, c0 as RegexpExtractExpr, R as RegexpExtractAllExpr, c1 as NumberToStrExpr, c2 as AliasesExpr, c3 as PosexplodeExpr, c4 as AddMonthsExpr, c5 as FormatExpr, w as DateTruncExpr, aJ as TimestampTruncExpr, c6 as TrimExpr, c7 as HexStringExpr, c8 as RoundExpr, ae as StrPositionExpr, c9 as StrtokExpr, ca as ApproxQuantileExpr, cb as ApproxQuantilesExpr, cc as JsonExtractScalarExpr, cd as BitwiseNotExpr, ce as WindowExpr, cf as FilterExpr, cg as CorrExpr, ch as LiteralExpr, ci as NegExpr, cj as HavingExpr } from '../tokens-qxb1e_iq.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Regex to detect time zones in timestamps of the form [+|-]TT[:tt]
|
|
@@ -23,7 +23,7 @@ declare const WS_CONTROL_CHARS_TO_DUCK: Record<string, number>;
|
|
|
23
23
|
* ISO 8601 standard: Monday=1, ..., Sunday=7
|
|
24
24
|
*/
|
|
25
25
|
declare const WEEK_START_DAY_TO_DOW: Record<string, number>;
|
|
26
|
-
declare const MAX_BIT_POSITION:
|
|
26
|
+
declare const MAX_BIT_POSITION: LiteralExpr | NegExpr;
|
|
27
27
|
/**
|
|
28
28
|
* SEQ function constants
|
|
29
29
|
*/
|
|
@@ -127,6 +127,7 @@ declare class DuckDBParser extends Parser {
|
|
|
127
127
|
table?: typeof Expression | undefined;
|
|
128
128
|
warehouse?: typeof Expression | undefined;
|
|
129
129
|
stage?: typeof Expression | undefined;
|
|
130
|
+
stream?: typeof Expression | undefined;
|
|
130
131
|
streamlit?: typeof Expression | undefined;
|
|
131
132
|
var?: typeof Expression | undefined;
|
|
132
133
|
bitString?: typeof Expression | undefined;
|
|
@@ -540,6 +541,7 @@ declare class DuckDBParser extends Parser {
|
|
|
540
541
|
parsePrimary(): Expression | undefined;
|
|
541
542
|
}
|
|
542
543
|
declare class DuckDBGenerator extends Generator {
|
|
544
|
+
static get STRTOK_TEMPLATE(): Expression;
|
|
543
545
|
static get AFTER_HAVING_MODIFIER_TRANSFORMS(): Map<string, (this: Generator, e: Expression) => string>;
|
|
544
546
|
static SUPPORTS_DECODE_CASE: boolean;
|
|
545
547
|
static readonly SELECT_KINDS: string[];
|
|
@@ -560,6 +562,7 @@ declare class DuckDBGenerator extends Generator {
|
|
|
560
562
|
static IGNORE_NULLS_IN_FUNC: boolean;
|
|
561
563
|
static IGNORE_NULLS_BEFORE_ORDER: boolean;
|
|
562
564
|
static JSON_PATH_BRACKETED_KEY_SUPPORTED: boolean;
|
|
565
|
+
static SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY: boolean;
|
|
563
566
|
static SUPPORTS_CREATE_TABLE_LIKE: boolean;
|
|
564
567
|
static MULTI_ARG_DISTINCT: boolean;
|
|
565
568
|
static CAN_IMPLEMENT_ARRAY_ANY: boolean;
|
|
@@ -656,6 +659,7 @@ declare class DuckDBGenerator extends Generator {
|
|
|
656
659
|
regexplikeSql(expression: RegexpLikeExpr): string;
|
|
657
660
|
arrayoverlapsSql(expression: ArrayOverlapsExpr): string;
|
|
658
661
|
arraycontainsSql(expression: ArrayContainsExpr): string;
|
|
662
|
+
arrayUniqueAggSql(expression: ArrayUniqueAggExpr): string;
|
|
659
663
|
arraydistinctSql(expression: ArrayDistinctExpr): string;
|
|
660
664
|
regexpinstrSql(expression: RegexpInstrExpr): string;
|
|
661
665
|
regexpreplaceSql(expression: RegexpReplaceExpr): string;
|
|
@@ -668,6 +672,7 @@ declare class DuckDBGenerator extends Generator {
|
|
|
668
672
|
arrayintersectSql(expression: ArrayIntersectExpr): string;
|
|
669
673
|
arrayexceptSql(expression: ArrayExceptExpr): string;
|
|
670
674
|
currentDateSql(expression: CurrentDateExpr): string;
|
|
675
|
+
checkJsonSql(expression: CheckJsonExpr): string;
|
|
671
676
|
parseJsonSql(expression: ParseJsonExpr): string;
|
|
672
677
|
truncSql(expression: TruncExpr): string;
|
|
673
678
|
normalSql(expression: NormalExpr): string;
|
|
@@ -747,6 +752,8 @@ declare class DuckDBGenerator extends Generator {
|
|
|
747
752
|
trimSql(expression: TrimExpr): string;
|
|
748
753
|
hexStringSql(expression: HexStringExpr): string;
|
|
749
754
|
roundSql(expression: RoundExpr): string;
|
|
755
|
+
strPositionSql(expression: StrPositionExpr): string;
|
|
756
|
+
strtokSql(expression: StrtokExpr): string;
|
|
750
757
|
approxQuantileSql(expression: ApproxQuantileExpr): string;
|
|
751
758
|
approxQuantilesSql(expression: ApproxQuantilesExpr): string;
|
|
752
759
|
jsonExtractScalarSql(expression: JsonExtractScalarExpr): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as Dialect, a as Dialects, a5 as NullOrdering, N as NormalizationStrategy, E as Expression, a8 as TypeAnnotator, i as DataTypeExprKind, d as Tokenizer, e as TokenPair, f as TokenType, g as Parser,
|
|
1
|
+
import { D as Dialect, a as Dialects, a5 as NullOrdering, N as NormalizationStrategy, E as Expression, a8 as TypeAnnotator, i as DataTypeExprKind, d as Tokenizer, e as TokenPair, f as TokenType, g as Parser, aU as ShowExpr, aA as DataTypeExpr, aV as TableSampleExpr, aW as ToMapExpr, aX as MapExpr, aY as AttachExpr, ak as DetachExpr, aZ as InstallExpr, m as CommandExpr, h as Generator, v as PropertiesLocation, a_ as LastValueExpr, a$ as TimeSliceExpr, b0 as BitmapBucketNumberExpr, b1 as BitmapBitPositionExpr, b2 as BitmapConstructAggExpr, b3 as NthValueExpr, b4 as RandstrExpr, b5 as ZipfExpr, b6 as ToBinaryExpr, b7 as GreatestExpr, b8 as LeastExpr, b9 as GeneratorExpr, ba as LambdaExpr, bb as SortArrayExpr, bc as ApproxTopKExpr, bd as FromIso8601TimestampExpr, a0 as StrToTimeExpr, av as StrToDateExpr, be as TsOrDsToTimeExpr, bf as RegexpLikeExpr, bg as ArrayOverlapsExpr, W as ArrayContainsExpr, bh as ArrayUniqueAggExpr, bi as ArrayDistinctExpr, bj as RegexpInstrExpr, bk as RegexpReplaceExpr, bl as RegexpCountExpr, bm as ArrayIntersectExpr, bn as ArrayExceptExpr, aL as CurrentDateExpr, bo as CheckJsonExpr, bp as ParseJsonExpr, bq as TruncExpr, br as NormalExpr, aO as UniformExpr, bs as TimeFromPartsExpr, aa as ExtractExpr, bt as TimestampFromPartsExpr, bu as TimestampLtzFromPartsExpr, bv as TimestampTzFromPartsExpr, aM as ColumnDefExpr, ag as JoinExpr, O as GenerateSeriesExpr, bw as CountIfExpr, I as BracketExpr, bx as WithinGroupExpr, by as LengthExpr, $ as LevenshteinExpr, bz as PadExpr, bA as MinhashExpr, bB as MinhashCombineExpr, bC as ApproximateSimilarityExpr, bD as ArraySliceExpr, bE as ArraysZipExpr, bF as LowerExpr, bG as UpperExpr, bH as ReverseExpr, bI as RandExpr, bJ as RightExpr, bK as Base64EncodeExpr, bL as ReplaceExpr, bM as BinaryExpr, bN as BitwiseXorExpr, bO as ObjectInsertExpr, bP as MapCatExpr, bQ as MapDeleteExpr, bR as MapSizeExpr, bS as MapPickExpr, bT as MapInsertExpr, bU as StartsWithExpr, bV as SpaceExpr, bW as TableFromRowsExpr, U as UnnestExpr, bX as IgnoreNullsExpr, bY as SplitExpr, bZ as SplitPartExpr, b_ as RespectNullsExpr, b$ as ArrayToStringExpr, c0 as RegexpExtractExpr, R as RegexpExtractAllExpr, c1 as NumberToStrExpr, c2 as AliasesExpr, c3 as PosexplodeExpr, c4 as AddMonthsExpr, c5 as FormatExpr, w as DateTruncExpr, aJ as TimestampTruncExpr, c6 as TrimExpr, c7 as HexStringExpr, c8 as RoundExpr, ae as StrPositionExpr, c9 as StrtokExpr, ca as ApproxQuantileExpr, cb as ApproxQuantilesExpr, cc as JsonExtractScalarExpr, cd as BitwiseNotExpr, ce as WindowExpr, cf as FilterExpr, cg as CorrExpr, ch as LiteralExpr, ci as NegExpr, cj as HavingExpr } from '../tokens-qxb1e_iq.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Regex to detect time zones in timestamps of the form [+|-]TT[:tt]
|
|
@@ -23,7 +23,7 @@ declare const WS_CONTROL_CHARS_TO_DUCK: Record<string, number>;
|
|
|
23
23
|
* ISO 8601 standard: Monday=1, ..., Sunday=7
|
|
24
24
|
*/
|
|
25
25
|
declare const WEEK_START_DAY_TO_DOW: Record<string, number>;
|
|
26
|
-
declare const MAX_BIT_POSITION:
|
|
26
|
+
declare const MAX_BIT_POSITION: LiteralExpr | NegExpr;
|
|
27
27
|
/**
|
|
28
28
|
* SEQ function constants
|
|
29
29
|
*/
|
|
@@ -127,6 +127,7 @@ declare class DuckDBParser extends Parser {
|
|
|
127
127
|
table?: typeof Expression | undefined;
|
|
128
128
|
warehouse?: typeof Expression | undefined;
|
|
129
129
|
stage?: typeof Expression | undefined;
|
|
130
|
+
stream?: typeof Expression | undefined;
|
|
130
131
|
streamlit?: typeof Expression | undefined;
|
|
131
132
|
var?: typeof Expression | undefined;
|
|
132
133
|
bitString?: typeof Expression | undefined;
|
|
@@ -540,6 +541,7 @@ declare class DuckDBParser extends Parser {
|
|
|
540
541
|
parsePrimary(): Expression | undefined;
|
|
541
542
|
}
|
|
542
543
|
declare class DuckDBGenerator extends Generator {
|
|
544
|
+
static get STRTOK_TEMPLATE(): Expression;
|
|
543
545
|
static get AFTER_HAVING_MODIFIER_TRANSFORMS(): Map<string, (this: Generator, e: Expression) => string>;
|
|
544
546
|
static SUPPORTS_DECODE_CASE: boolean;
|
|
545
547
|
static readonly SELECT_KINDS: string[];
|
|
@@ -560,6 +562,7 @@ declare class DuckDBGenerator extends Generator {
|
|
|
560
562
|
static IGNORE_NULLS_IN_FUNC: boolean;
|
|
561
563
|
static IGNORE_NULLS_BEFORE_ORDER: boolean;
|
|
562
564
|
static JSON_PATH_BRACKETED_KEY_SUPPORTED: boolean;
|
|
565
|
+
static SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY: boolean;
|
|
563
566
|
static SUPPORTS_CREATE_TABLE_LIKE: boolean;
|
|
564
567
|
static MULTI_ARG_DISTINCT: boolean;
|
|
565
568
|
static CAN_IMPLEMENT_ARRAY_ANY: boolean;
|
|
@@ -656,6 +659,7 @@ declare class DuckDBGenerator extends Generator {
|
|
|
656
659
|
regexplikeSql(expression: RegexpLikeExpr): string;
|
|
657
660
|
arrayoverlapsSql(expression: ArrayOverlapsExpr): string;
|
|
658
661
|
arraycontainsSql(expression: ArrayContainsExpr): string;
|
|
662
|
+
arrayUniqueAggSql(expression: ArrayUniqueAggExpr): string;
|
|
659
663
|
arraydistinctSql(expression: ArrayDistinctExpr): string;
|
|
660
664
|
regexpinstrSql(expression: RegexpInstrExpr): string;
|
|
661
665
|
regexpreplaceSql(expression: RegexpReplaceExpr): string;
|
|
@@ -668,6 +672,7 @@ declare class DuckDBGenerator extends Generator {
|
|
|
668
672
|
arrayintersectSql(expression: ArrayIntersectExpr): string;
|
|
669
673
|
arrayexceptSql(expression: ArrayExceptExpr): string;
|
|
670
674
|
currentDateSql(expression: CurrentDateExpr): string;
|
|
675
|
+
checkJsonSql(expression: CheckJsonExpr): string;
|
|
671
676
|
parseJsonSql(expression: ParseJsonExpr): string;
|
|
672
677
|
truncSql(expression: TruncExpr): string;
|
|
673
678
|
normalSql(expression: NormalExpr): string;
|
|
@@ -747,6 +752,8 @@ declare class DuckDBGenerator extends Generator {
|
|
|
747
752
|
trimSql(expression: TrimExpr): string;
|
|
748
753
|
hexStringSql(expression: HexStringExpr): string;
|
|
749
754
|
roundSql(expression: RoundExpr): string;
|
|
755
|
+
strPositionSql(expression: StrPositionExpr): string;
|
|
756
|
+
strtokSql(expression: StrtokExpr): string;
|
|
750
757
|
approxQuantileSql(expression: ApproxQuantileExpr): string;
|
|
751
758
|
approxQuantilesSql(expression: ApproxQuantilesExpr): string;
|
|
752
759
|
jsonExtractScalarSql(expression: JsonExtractScalarExpr): string;
|
package/dist/dialects/duckdb.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import{a as Ca}from"../chunk-3OVM5ZRR.js";import"../chunk-KNRQDMQ7.js";import{$d as Ps,$i as Ir,$m as pn,$q as ls,$v as pa,$w as Na,Ad as wt,Al as kr,Am as zr,Aq as ni,Ar as gi,At as Ce,Bi as Wt,Bl as zt,Bm as tn,Bn as _n,Bo as et,Bq as ps,Br as Ai,Bt as ji,Cj as Fs,Cn as On,Co as ce,Cq as ii,Cr as xi,Cu as y,Dd as er,Dj as Mr,Dk as jt,Dl as ts,Dm as te,Dn as Ln,Do as vn,Dp as Se,Dq as xe,Dr as Ri,Ef as Tr,Ei as Ar,Ek as br,Ep as fe,Eq as ai,Ev as ra,Ew as Ra,Fi as ut,Fj as $t,Fk as Dr,Fn as re,Fo as le,Fv as xs,Fw as ma,Gh as qs,Gi as Z,Gj as ht,Gk as Gr,Gl as Zs,Gn as Pn,Gq as Re,Gv as Ct,Hc as Kt,He as Er,Hj as Us,Hn as Cn,Ho as Vn,Hp as jn,Hr as mi,Hs as yi,If as ys,Ik as Fr,Io as Xn,Iu as ye,Jb as $e,Ji as _t,Jk as Ft,Jm as sn,Jn as Mn,Jo as kn,Jq as me,Jr as di,Js as qi,Jv as qe,Ke as Cs,Kj as Hs,Kl as Kr,Kn as yn,Kq as de,Kr as Ii,Ks as bi,Ku as g,Lq as Ie,Lu as zi,Lv as na,Ma as dt,Me as pr,Mi as q,Mj as Tt,Mn as ns,Mq as Ne,Mv as x,Nj as St,Nv as ia,Oe as it,Oj as Gt,Om as en,Op as Qn,Or as Ni,Ou as ta,Pi as B,Pk as Vs,Pl as ss,Pr as z,Pu as sa,Pv as aa,Ql as Ut,Qn as qn,Qr as wi,Qs as Ht,Qw as da,Rb as Je,Rd as rr,Re as Ms,Ri as xr,Rk as m,Rl as Wr,Rn as ne,Rp as zn,Rr as _i,Rs as Di,Rt as Qi,Rv as oa,Rw as Mt,Sa as R,Sb as Ze,Sj as G,Sl as $r,Sm as es,So as ue,Sr as Oi,Ss as Gi,Tb as je,Tf as Sr,Ti as Rr,Tk as W,Tm as se,Tq as oi,Tr as Li,Ts as Fi,Uc as Ls,Ue as cr,Ul as $,Um as rn,Un as bn,Uq as we,Vc as tr,Vi as mr,Vj as Jt,Vl as T,Vm as ee,Vp as ti,Vq as Ei,Vs as Ui,We as lr,Wj as w,Wk as Ur,Wq as pi,Wr as Pi,Ws as Hi,Xh as gr,Xj as yr,Xk as Hr,Xm as nn,Xn as ie,Xs as Bi,Yc as It,Ye as ur,Ym as an,Yn as Dn,Yq as cs,Yv as Ea,Zi as dr,Zj as Zt,Zm as on,Zn as is,Zr as us,Zs as Yi,Zt as Me,Zu as b,_a as _s,_m as En,_n as ae,_r as gt,_w as Ia,a as p,ab as Ke,ae as P,ao as Gn,ap as Kn,b as yt,bc as Qe,bj as bs,bn as cn,br as Pt,bs as Le,bt as vi,bu as Yt,bw as be,bx as wa,c as qt,cc as ze,ce as nr,cj as Nr,cn as ln,co as Fn,cp as as,cu as gs,cw as ca,d as bt,dm as Jr,dn as un,dp as Wn,dw as la,e as S,em as js,en as hn,eo as Un,ep as he,er as ci,et as Vi,ev as v,fm as Zr,fn as Tn,fo as Hn,ft as Xi,fu as At,fw as ua,ge as ir,gm as Lt,gr as li,gw as De,gx as Ue,hn as Sn,hp as $n,ht as ki,hu as X,hx as _a,ib as kt,ic as Dt,ij as I,in as fn,it as Bt,iv as As,jb as Os,jf as H,jn as gn,jq as os,jt as Ki,jx as Oa,ke as ar,kj as wr,kn as An,kr as ui,ks as hs,kt as Wi,kw as Ge,le as or,lh as fr,lj as Ds,ll as Xs,ln as xn,lr as hi,ls as Ts,lt as $i,lx as La,mf as hr,mj as _r,ml as ks,mn as Rn,mq as Q,ms as Pe,nb as We,ne as l,nj as Or,nn as mn,no as oe,np as Jn,ns as Ci,nt as Ji,nw as ha,ob as F,oj as Lr,oo as Bn,ot as Zi,ow as Ta,pj as at,pw as Sa,px as Pa,q as K,ql as Ks,qm as jr,qo as Ee,qr as ft,qu as ot,rg as a,rl as Ws,ro as pe,ru as Et,s as f,sd as Nt,sl as Br,sn as rs,so as Yn,sp as Zn,sw as fa,sx as vt,tj as Gs,tl as Qt,tu as N,tw as ga,uj as Pr,uk as Bs,ul as Yr,um as Qs,uq as si,ur as Ti,ut as Ss,uw as Fe,vd as sr,vj as Y,vl as vr,vn as dn,vq as ge,vr as _e,vt as fs,wb as d,wj as Cr,wk as Ys,wl as $s,wn as In,wp as j,wq as Es,xl as Js,xm as Qr,xn as Nn,xq as Ae,xr as Oe,xs as Mi,xw as Aa,yj as Ot,yk as vs,yl as Vr,yn as wn,yq as ei,yr as Si,yv as ea,zi as st,zk as qr,zl as Xr,zm as zs,zp as Te,zq as ri,zr as fi,zw as xa}from"../chunk-RGKTYIN3.js";var tE=/:\d{2}.*?[+\-]\d{2}(?::\d{2})?/,Ma={"\\":"\\\\","-":"\\-","^":"\\^","[":"\\[","]":"\\]"},sE="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",eE=123456,Rs={"\v":11,"":28,"":29,"":30,"":31},Is={MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6,SUNDAY:7},rE=a.number(32768),nE=y("(ROW_NUMBER() OVER (ORDER BY 1) - 1)"),iE=new Map([[me,1],[de,2],[Ie,4],[Ne,8]]),aE=[ar,tr,xr,wt,st];function Wo(n,o,s={}){let{reverse:t=!1}=s;if(o instanceof a&&o.isString){let r=o.args.this??"";for(let i=0;i<Math.min(3,r.length);i++){let E="+/="[i],c=r[i]??"";if(c!==E){let[h,A]=t?[c,E]:[E,c];n=new ai({this:n,expression:a.string(h),replacement:a.string(A)})}}}return n}p(Wo,"applyBase64AlphabetReplacements");function ya(n,o){let{toString:s=!1}=o,t=n.args.this,e=n.args.alphabet;return t=Wo(t??g(),e,{reverse:!0}),t=new Gn({this:t}),s&&(t=new ns({this:t})),this.sql(t)}p(ya,"base64DecodeSql");function oE(n){let o=n.args.this,s=n.text("unit").toUpperCase();if(!s||s==="MONTH")return this.func("LAST_DAY",[o]);if(s==="YEAR"){let t=N("EXTRACT","YEAR",o),e=N("MAKE_DATE",t,a.number(12),a.number(31));return this.sql(e)}if(s==="QUARTER"){let t=N("EXTRACT","YEAR",o),e=N("EXTRACT","QUARTER",o),r=new St({this:e,expression:a.number(3)}),i=N("MAKE_DATE",t,r,a.number(1)),E=N("LAST_DAY",i);return this.sql(E)}if(s==="WEEK"){let t=N("EXTRACT","DAYOFWEEK",o),e=new Tt({this:new w({this:new G({this:a.number(7),expression:t})}),expression:a.number(7)}),r=new B({this:e,unit:new P({this:"DAY"})}),i=new I({this:o,expression:r});return this.sql(Et(i,"date"))}return this.unsupported(`Unsupported date part '${s}' in LAST_DAY function`),this.functionFallbackSql(n)}p(oE,"lastDaySql");function ke(n){return(n instanceof P||n instanceof a)&&n.name.toUpperCase()==="NANOSECOND"}p(ke,"isNanosecondUnit");function $o(n,o){let s=new T({this:n,to:new l({this:"timestampNs"})}),t=new T({this:o,to:new l({this:"timestampNs"})});return this.sql(new G({this:this.func("EPOCH_NS",[s]),expression:this.func("EPOCH_NS",[t])}))}p($o,"handleNanosecondDiff");function EE(n){let o=n.args.this,s=n.args.safe??!1,t=new $({}).when(new us({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("ON")),new Z({this:!0})).when(new us({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("OFF")),new Z({this:!1})),e;if(s)e=t.else(N("TRY_CAST",o,l.build("BOOLEAN")));else{let r=N("TRY_CAST",o,l.build("REAL")),i=new Bt({this:N("ISNAN",r),expression:N("ISINF",r)});e=t.when(i,N("ERROR",a.string("TO_BOOLEAN: Non-numeric values NaN and INF are not supported"))).else(new T({this:o,to:new l({this:"boolean"})}))}return this.sql(e)}p(EE,"toBooleanSql");function pE(n){let o=n.args.this,s=this.sql(n,"zone");if(s){o=new T({this:o,to:new l({this:"timestamp"})});let t=new it({this:o,zone:a.string("UTC")});o=new it({this:t,zone:s})}return this.sql(new T({this:o,to:new l({this:"date"})}))}p(pE,"dateSql");function cE(n){let o=n.args.unit;if(ke(o))return $o.call(this,n.args.expression??g(),n.args.this??g());let s=new T({this:n.args.this,to:new l({this:"time"})}),t=new T({this:n.args.expression,to:new l({this:"time"})});return this.func("DATE_DIFF",[Mt(n),t,s])}p(cE,"timeDiffSql");function rt(n={}){let{cast:o=!0}=n,s=da({cast:o});return function(t){let e=K(t.getArgKey("unit"),"string",d),r=t.args.expression;if(ke(e instanceof d?e:void 0)){r instanceof B&&(r=r.args.this);let i=new T({this:K(t.args.this,"string",d),to:new l({this:"timestampNs"})});return this.sql(this.func("MAKE_TIMESTAMP_NS",[new I({this:this.func("EPOCH_NS",[i]),expression:K(r,"string",d)})]))}return!r||r instanceof B?s.call(this,t):(v(r,l.REAL_TYPES)&&t.setArgKey("expression",new T({this:this.func("ROUND",[r]),to:new l({this:"int"})})),s.call(this,t))}}p(rt,"dateDeltaToBinaryIntervalOp");function lE(n){let o=n.args.this,s=n.args.position,t=n.args.expression,e=new W({expressions:[t??g()]}),r=n.args.offset??0;if(!s?.isNumber)return this.unsupported("ARRAY_INSERT can only be transpiled with a literal position"),this.func("ARRAY_INSERT",[o,s,t]);let i=s.toValue();0<i?i-=r:i<0&&(i+=r);let E;if(i===0)E=[e,o??g()];else if(0<i){let c=new q({this:o,expressions:[new H({this:a.number(1),expression:a.number(i)})]}),h=new q({this:o,expressions:[new H({this:a.number(i+1)})]});E=[c,e,h]}else{let c=new j({this:o}),h=new I({this:c,expression:a.number(i)}),A=new I({this:h,expression:a.number(1)}),O=new q({this:o,expressions:[new H({this:a.number(1),expression:h})]}),M=new q({this:o,expressions:[new H({this:A})]});E=[O,e,M]}return this.sql(new et({this:new ht({this:o,expression:g()}),true:g(),false:this.func("LIST_CONCAT",E)}))}p(lE,"arrayInsertSql");function uE(n){let o=n.args.this,s=n.args.position;if(!s?.isNumber)return this.unsupported("ARRAY_REMOVE_AT can only be transpiled with a literal position"),this.func("ARRAY_REMOVE_AT",[o,s]);let t=s.toValue(),e;if(t===0)e=new q({this:o,expressions:[new H({this:a.number(2)})]});else if(0<t){let r=new q({this:o,expressions:[new H({this:a.number(1),expression:a.number(t)})]}),i=new q({this:o,expressions:[new H({this:a.number(t+2)})]});e=this.func("LIST_CONCAT",[r,i])}else if(t===-1){let r=new j({this:o}),i=new I({this:r,expression:a.number(-1)});e=new q({this:o,expressions:[new H({this:a.number(1),expression:i})]})}else{let r=new j({this:o}),i=new I({this:r,expression:a.number(t)}),E=new I({this:i,expression:a.number(2)}),c=new q({this:o,expressions:[new H({this:a.number(1),expression:i})]}),h=new q({this:o,expressions:[new H({this:E})]});e=this.func("LIST_CONCAT",[c,h])}return this.sql(new et({this:new ht({this:o,expression:g()}),true:g(),false:e}))}p(uE,"arrayRemoveAtSql");function hE(n){return n.args.expression&&this.unsupported("DuckDB's ARRAY_SORT does not support a comparator."),this.func("ARRAY_SORT",[n.args.this])}p(hE,"arraySortSql");function qa(n){return new cs({this:R(n,0),asc:new Z({this:!1})})}p(qa,"buildSortArrayDesc");function ba(n){return new Ws({this:R(n,1),expression:R(n,0)})}p(ba,"buildArrayPrepend");function Da(n){return new ee({this:R(n,2),expression:R(n,1),unit:R(n,0)})}p(Da,"buildDateDiff");function Ga(n={}){let{endExclusive:o=!1}=n;return s=>{s.length===1&&s.unshift(a.number("0"));let t=Xs.fromArgList(s);return t.setArgKey("isEndExclusive",o),t}}p(Ga,"buildGenerateSeries");function TE(n){return n.length===1?new z({this:R(n,0),scale:z.MICROS}):new Pi({year:R(n,0),month:R(n,1),day:R(n,2),hour:R(n,3),min:R(n,4),sec:R(n,5)})}p(TE,"buildMakeTimestamp");function Fa(...n){return function(){return this.parseShowDuckdb(n[0])}}p(Fa,"showParser");function SE(n){let o=n.findAncestor(T,st);if(o=o instanceof st?void 0:o,(!n.args.expressions||n.args.expressions.length===0)&&o instanceof T&&v(o.args.to,"map"))return"MAP()";let s=[],t=!n.find(Ot)&&o instanceof T&&[...o.findAll(l)].some(r=>v(r,"struct"));n.args.expressions?.forEach((r,i)=>{let E=r instanceof Ot,c=r.args.this,h=E?r.args.expression:r;if(t)s.push(this.sql(h));else{let A;c instanceof It?A=this.sql(a.string(r.name)):E?A=this.sql(r.args.this):A=this.sql(a.string(`_${i}`)),s.push(`${A}: ${this.sql(h)}`)}});let e=s.join(", ");return t?`ROW(${e})`:`{${e}}`}p(SE,"structSql");function fE(n){if(v(n,"array")){let o=this.expressions(n,{flat:!0}),s=this.expressions(n,{key:"values",flat:!0});return`${o}[${s}]`}if(v(n,["time","timetz","timestamptz"])){let o=n.args.this;return o instanceof d?o.name:o?Ke(o):""}return Ct.prototype.dataTypeSql.call(this,n)}p(fE,"dataTypeSql");function gE(n){return`CAST(${this.func("TO_JSON",[n.args.this,n.args.options])} AS TEXT)`}p(gE,"jsonFormatSql");function Jo(n,o,s){let t=o*8,e=a.number((2n**BigInt(t)).toString());if(s){let r=a.number((2n**BigInt(t-1)).toString());return b(Vt.SEQ_SIGNED.copy(),[],{base:n,maxVal:e,half:r})}return b(Vt.SEQ_UNSIGNED.copy(),[],{base:n,maxVal:e})}p(Jo,"buildSeqExpression");function AE(n){if(!(n instanceof st))return n;let o=n.args.from;return!o||!(o.args.this instanceof Nr)||!(o.args.this.args.this instanceof ks)?n:n.transform(s=>{let t=iE.get(s._constructor);return t!==void 0?Jo(new ys({this:X("range")}),t,s.name==="1"):s},{copy:!1})}p(AE,"seqToRangeInGenerator");function ms(n,o){let s=n.findAncestor(...aE);s&&(!(s instanceof wt||s instanceof st)||s instanceof wt&&s.parent instanceof Wt)&&this.unsupported("SEQ in restricted context is not supported - use CTE or subquery");let t=Jo(nE.copy(),o,n.name==="1");return this.sql(t)}p(ms,"seqSql");function xE(n){let o=n.args.scale,s=o?.toValue(),t=n.args.this,e=n.args.targetType,r=v(e,["timestamp","timestampntz"]);if(s===z.MILLIS.toValue())return this.func("EPOCH_MS",[t]);if(s===z.MICROS.toValue())return this.func("MAKE_TIMESTAMP",[t]);s!==void 0&&s!==z.SECONDS.toValue()&&(t=new at({this:t,expression:N("POW",a.number(10),o)}));let i=new m({this:"TO_TIMESTAMP",expressions:[t??g()]});return r&&(i=new it({this:i,zone:a.string("UTC")})),this.sql(i)}p(xE,"unixToTimeSql");var RE=[_t,q,Zt,Jt];function Ua(n){let o=aa.call(this,n);return!n.sameParent&&RE.some(s=>n.parent instanceof s)&&(o=this.wrap(o)),o}p(Ua,"arrowJsonExtractSqlDuckDB");function Rt(n,o="date"){if(n instanceof a&&n.isString){let s=n.args.this??"",t=o;return o==="date"&&s.includes(":")&&(t=tE.test(s)?"timestamptz":"timestamp"),new T({this:n,to:new l({this:t})})}return n}p(Rt,"implicitDatetimeCast");function Zo(n){if(n instanceof P&&"ISOWEEK".includes(n.name.toUpperCase()))return 1;if(n instanceof hr)return Is[n.name.toUpperCase()]}p(Zo,"weekUnitToDow");function Be(n,o,s={}){let{preserveStartDay:t=!1}=s,e=o===7?1:1-o,r=N("DATE_TRUNC",new P({this:"WEEK"}),n);if(e===0)return r;let i=new B({this:a.string(e.toString()),unit:new P({this:"DAY"})}),E=new es({this:n,expression:i});if(r.setArgKey("this",E),t){let c=new B({this:a.string((-e).toString()),unit:new P({this:"DAY"})});return Et(new es({this:r,expression:c}),"date")}return r}p(Be,"buildWeekTruncExpression");function Ha(n){let o=n.args.unit;if(ke(o))return $o.call(this,n.args.this??g(),n.args.expression??g());let s=Rt(n.args.this),t=Rt(n.args.expression),e=n.args.datePartBoundary,r=Zo(o);return e&&r!==void 0&&s&&t&&(n.setArgKey("unit",a.string("WEEK")),s=Be(s,r),t=Be(t,r)),this.func("DATE_DIFF",[Mt(n),t,s])}p(Ha,"dateDiffSql");function Ba(n){let o=n instanceof oe,s=o?"date":"timestamp",t=Rt(n.args.start,s),e=Rt(n.args.end,s),r=new Xs({start:t,end:e,step:n.args.step});return o&&(r=new T({this:r,to:l.build("ARRAY<DATE>")})),this.sql(r)}p(Ba,"generateDatetimeArraySql");function Ya(n){let o=n.args.expression instanceof d?n.args.expression:void 0,s=new as({this:n.args.this,expression:o}),t=n instanceof ue?"ARRAY<STRING>":"ARRAY<JSON>";return this.sql(new T({this:s,to:l.build(t)}))}p(Ya,"jsonExtractValueArraySql");function tt(n){if(n!==void 0)return n instanceof d&&n.type&&!v(n,[...l.TEXT_TYPES,"unknown"])?new T({this:n,to:new l({this:"varchar"})}):n instanceof d?n:a.string(n.toString())}p(tt,"castToVarchar");function Ye(n){return n&&!v(n,"boolean")?new T({this:n,to:new l({this:"boolean"})}):n}p(Ye,"castToBoolean");function J(n){return v(n,["binary","varbinary","blob"])}p(J,"isBinary");function pt(n,o){if(J(n)){let s=l.build("BLOB",{dialect:"duckdb"});o=this.sql(new T({this:o,to:s}))}return o}p(pt,"genWithCastToBlob");function ve(n){if(!J(n))return n;let o=n;return n instanceof Tr&&(o=new Ii({this:a.string(n.args.this)})),new T({this:o,to:new l({this:"bit"})})}p(ve,"castToBit");function va(n){n.args.this instanceof d&&J(n.args.this)&&n.setArgKey("this",ve(n.args.this)),n.args.expression instanceof d&&J(n.args.expression)&&n.setArgKey("expression",ve(n.args.expression))}p(va,"prepareBinaryBitwiseArgs");function Va(n){let o=n.args.this,s=n.args.expression,t=N("ISODOW",o),e;if(s instanceof a){let i=(s.args.this??"").toUpperCase(),E=Object.keys(Is).find(c=>c.startsWith(i));if(E)e=a.number(Is[E]);else return this.functionFallbackSql(n)}else{let i=new us({this:s});e=new $({ifs:Object.entries(Is).map(([E,c])=>new et({this:this.func("STARTS_WITH",[i.copy(),a.string(E.substring(0,2))]),true:a.number(c)}))})}let r;if(n instanceof Le){let i=At(e.sub(t).add(6),{copy:!1}),E=new Tt({this:i,expression:a.number(7)}).add(1);r=new I({this:o,expression:new B({this:E,unit:new P({this:"DAY"})})})}else{let i=At(t.sub(e).add(6),{copy:!1}),E=new Tt({this:i,expression:a.number(7)}).add(1);r=new G({this:o,expression:new B({this:E,unit:new P({this:"DAY"})})})}return this.sql(new T({this:r,to:new l({this:"date"})}))}p(Va,"dayNavigationSql");function mE(n){let o=n.args.this;if(o instanceof lr){let s=o.args.max?"ARG_MAX_NULL":"ARG_MIN_NULL";return this.func(s,[o.args.this,o.args.expression])}return this.functionFallbackSql(n)}p(mE,"anyValueSql");function He(n){let o="BIT_XOR";n instanceof Ts?o="BIT_OR":n instanceof hs&&(o="BIT_AND");let s=n.args.this;return v(s,[...l.REAL_TYPES,...l.TEXT_TYPES])&&(v(s,l.FLOAT_TYPES)&&(s=this.func("ROUND",[s])),s=new T({this:s,to:new l({this:"int"})})),this.func(o,[s])}p(He,"bitwiseAggSql");function dE(n){let o=n.split("");if(!o.some(i=>i in Rs))return this.sql(a.string(n));let s=[],t=[],e=!1;for(let i of o){let E=i in Rs;E!==e&&(0<t.length&&(e?t.forEach(c=>s.push(this.func("CHR",[a.number(Rs[c])]))):s.push(this.sql(a.string(t.join(""))))),t=[],e=E),t.push(i)}0<t.length&&(e?t.forEach(i=>s.push(this.func("CHR",[a.number(Rs[i])]))):s.push(this.sql(a.string(t.join("")))));let r=s.join(" || ");return s.length===1?r:`(${r})`}p(dE,"literalSqlWithWsChr");function IE(n,o){if(!n)return o;if(n instanceof a&&n.isString){let e=(n.args.this??"").split("").map(r=>Ma[r]??r).join("");return dE.call(this,e)}let s=o;return Object.entries(Ma).forEach(([t,e])=>{s=this.func("REPLACE",[s,this.sql(a.string(t)),this.sql(a.string(e))])}),s}p(IE,"escapeRegexMetachars");function NE(n,o){if(o==="''")return`UPPER(LEFT(${n}, 1)) || LOWER(SUBSTRING(${n}, 2))`;let s=`CONCAT('[', ${o}, ']')`,t=`CONCAT('([', ${o}, ']+|[^', ${o}, ']+)')`;return this.func("ARRAY_TO_STRING",[new $({}).when(`REGEXP_MATCHES(LEFT(${n}, 1), ${s})`,this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])).else(this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])),"''"])}p(NE,"buildCapitalizationSql");function wE(n){let o=this.sql(n,"this"),s=n.args.expression;s||(s=a.string(this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS));let t=this.sql(s),e=IE.call(this,s,t);return NE.call(this,o,e)}p(wE,"initcapSql");function _E(n){return this.sql(new Y({this:new vi({this:Ye(n.args.this)??n.args.this}),expression:a.number(1)}))}p(_E,"boolxorAggSql");function Xa(n){let o=n instanceof Ds?"<<":">>",s=!1,t=n.args.this;t instanceof d&&J(t)?(s=!0,n.setArgKey("this",Et(t,"bit"))):n.args.requiresInt128&&t instanceof d&&t.replace(Et(t,"int128"));let e=this.binary(n,o);return n.parent instanceof _t&&(e=`(${e})`),s&&(e=this.sql(new T({this:e,to:l.build("BLOB",{dialect:"duckdb"})}))),e}p(Xa,"bitshiftSql");function OE(n,o){let s=n.args.decimals;if(!s||n.args.to)return;let t=n.args.this;t instanceof _t&&(t=new w({this:t}));let e=s.isInteger||s.isType([...l.INTEGER_TYPES])?s:new T({this:s,to:new l({this:"int"})}),r=new os({this:a.number("10"),expression:e}),i=new o({this:new St({this:t,expression:r})}),E=new at({this:i,expression:r.copy()});return this.roundSql(new Re({this:E,decimals:s,castsNonIntegerDecimals:!0}))}p(OE,"scaleRoundingSql");function ka(n){let o=OE.call(this,n,n._constructor);return o!==void 0?o:this.ceilFloor(n)}p(ka,"ceilFloor");function Ka(n){let o=n.args.this??g(),s=n.args.expression??g(),t,e,r;n instanceof Ce?(t=o,e=s,r="expression"):(t=s,e=o,r="this");let i=e.type;if(!i||typeof i=="string"||i.args.this==="unknown")try{let h=dt(n.copy(),{dialect:this.dialect}).args[r];i=h instanceof d?h.type:void 0}catch{}(!i||typeof i=="string"||i.args.this==="unknown")&&(i=l.build("DOUBLE"));let E=new T({this:g(),to:i});return this.sql(new et({this:new ht({this:t.copy(),expression:g()}),true:E,false:e.copy()}))}p(Ka,"regrValSql");function LE(n){let o=n;for(;o instanceof Wt||o instanceof Kt;)o=o.args.this??g();if(!(!(o instanceof gt)||!o.args.nullOnZeroVariance))return o.setArgKey("nullOnZeroVariance",!1),n}p(LE,"maybeCorrNullToFalse");function PE(n){let o=n.args.year,s=n.args.month,t=n.args.day;if(n.args.allowOverflow){let e=new m({this:"MAKE_DATE",expressions:[o??g(),a.number(1),a.number(1)]});return s&&(e=new I({this:e,expression:new B({this:new G({this:ye(s,_t),expression:a.number(1)}),unit:new P({this:"MONTH"})})})),t&&(e=new I({this:e,expression:new B({this:new G({this:ye(t,_t),expression:a.number(1)}),unit:new P({this:"DAY"})})})),this.sql(new T({this:e,to:new l({this:"date"})}))}return this.func("MAKE_DATE",[o,s,t])}p(PE,"dateFromPartsSql");function mt(n,o){return o?new Re({this:n,decimals:a.number(0)}):n}p(mt,"roundArg");function CE(n){let o=mt(n.args.this??g(),n.args.roundInput);return this.sql(new Jt({this:new w({this:o})}))}p(CE,"boolnotSql");function ME(n){let o=n.args.roundInput,s=mt(n.args.this??g(),o),t=mt(n.args.expression??g(),o);return this.sql(new w({this:new ki({this:new w({this:s}),expression:new w({this:t})})}))}p(ME,"boolandSql");function yE(n){let o=n.args.roundInput,s=mt(n.args.this??g(),o),t=mt(n.args.expression??g(),o);return this.sql(new w({this:new Bt({this:new w({this:s}),expression:new w({this:t})})}))}p(yE,"boolorSql");function qE(n){let o=n.args.roundInput,s=n.args.this&&mt(n.args.this,o),t=n.args.expression&&mt(n.args.expression,o);return this.sql(gs([At(Yt([s?.copy(),At(t.not())],{wrap:!1})),At(Yt([At(s.not()),t?.copy()],{wrap:!1}))],{wrap:!1}))}p(qE,"xorSql");function ds(n,o,s={}){let{isBinary:t=!1}=s,e=n.args.this;o==="SHA256"&&(n.text("length")||"256")!=="256"&&this.unsupported("DuckDB only supports SHA256 hashing algorithm."),e instanceof d&&e.type&&(!(e.type instanceof d)||e.type.args.this!=="unknown")&&!e.isType(l.TEXT_TYPES)&&!J(e)&&(e=new T({this:e,to:new l({this:"varchar"})}));let r=this.func(o,[e]);return t?this.func("UNHEX",[r]):r}p(ds,"shaSql");var Wa,$a,Ja,Za,ja,Qa,za,ct,V=class V extends(za=vt,Qa=[f],ja=[f],Za=[f],Ja=[f],$a=[f],Wa=[f],za){static get BYTE_STRINGS(){return[["e'","'"],["E'","'"]]}static get BYTE_STRING_ESCAPES(){return["'","\\"]}static get HEREDOC_STRINGS(){return["$"]}static get ORIGINAL_KEYWORDS(){let s={...vt.KEYWORDS,"//":"div","**":"dstar","^@":"caretAt","@>":"atGt","<@":"ltAt",ATTACH:"attach",BINARY:"varbinary",BITSTRING:"bit",BPCHAR:"text",CHAR:"text",DATETIME:"timestampntz",DETACH:"detach",FORCE:"force",INSTALL:"install",INT8:"bigint",LOGICAL:"boolean",MACRO:"function",ONLY:"only",PIVOT_WIDER:"pivot",POSITIONAL:"positional",RESET:"command",ROW:"struct",SIGNED:"int",STRING:"text",SUMMARIZE:"summarize",TIMESTAMP:"timestampntz",TIMESTAMP_S:"timestampS",TIMESTAMP_MS:"timestampMs",TIMESTAMP_NS:"timestampNs",TIMESTAMP_US:"timestamp",UBIGINT:"ubigint",UINTEGER:"uint",USMALLINT:"usmallint",UTINYINT:"utinyint",VARCHAR:"text"};return delete s["/*+"],s}static get SINGLE_TOKENS(){return{...vt.SINGLE_TOKENS,$:"parameter"}}static get COMMANDS(){let s=new Set(vt.COMMANDS);return s.delete("show"),s}};ct=yt(za),S(ct,10,"BYTE_STRINGS",Qa,V),S(ct,10,"BYTE_STRING_ESCAPES",ja,V),S(ct,10,"HEREDOC_STRINGS",Za,V),S(ct,10,"ORIGINAL_KEYWORDS",Ja,V),S(ct,10,"SINGLE_TOKENS",$a,V),S(ct,10,"COMMANDS",Wa,V),qt(ct,V),bt(ct,3,V),p(V,"DuckDBTokenizer"),V.HEREDOC_TAG_IS_IDENTIFIER=!0,V.HEREDOC_STRING_ALTERNATIVE="parameter";var Ve=V,to,so,eo,ro,no,io,ao,oo,Eo,po,co,lo,uo,ho,To,So,D,C=class C extends(So=F,To=[f],ho=[f],uo=[f],lo=[f],co=[f],po=[f],Eo=[f],oo=[f],ao=[f],io=[f],no=[f],ro=[f],eo=[f],so=[f],to=[f],So){static get NO_PAREN_FUNCTIONS(){let s={...F.NO_PAREN_FUNCTIONS};return s.sessionUser=en,s.currentCatalog=sn,s}static get BITWISE(){return(()=>{let s={...F.BITWISE};return delete s.caret,s})()}static get RANGE_PARSERS(){return{...F.RANGE_PARSERS,damp:kt(ss),caretAt:kt(ci),tilde:kt(ri)}}static get EXPONENT(){return{...F.EXPONENT,caret:os,dstar:os}}static get FUNCTIONS_WITH_ALIASED_ARGS(){return new Set([...F.FUNCTIONS_WITH_ALIASED_ARGS,"STRUCT_PACK"])}static get SHOW_PARSERS(){return{TABLES:Fa("TABLES"),"ALL TABLES":Fa("ALL TABLES")}}static get FUNCTIONS(){return(()=>{let s={...F.FUNCTIONS,ANY_VALUE:p(t=>new cr({this:Ht.fromArgList(t)}),"ANY_VALUE"),APPROX_QUANTILE:p(t=>Me.fromArgList(t),"APPROX_QUANTILE"),ARRAY_PREPEND:ba,ARRAY_INTERSECT:p(t=>new Kr({expressions:t}),"ARRAY_INTERSECT"),ARRAY_REVERSE_SORT:qa,ARRAY_SORT:p(t=>cs.fromArgList(t),"ARRAY_SORT"),BIT_AND:p(t=>hs.fromArgList(t),"BIT_AND"),BIT_OR:p(t=>Ts.fromArgList(t),"BIT_OR"),BIT_XOR:p(t=>Pe.fromArgList(t),"BIT_XOR"),DATEDIFF:Da,DATE_DIFF:Da,DATE_TRUNC:p(t=>Ge([R(t,0),R(t,1)]),"DATE_TRUNC"),DATETRUNC:p(t=>Ge([R(t,0),R(t,1)]),"DATETRUNC"),DECODE:p(t=>new ns({this:R(t,0),charset:a.string("utf-8")}),"DECODE"),EDITDIST3:p(t=>Te.fromArgList(t),"EDITDIST3"),ENCODE:p(t=>new ne({this:R(t,0),charset:a.string("utf-8")}),"ENCODE"),EPOCH:p(t=>Oe.fromArgList(t),"EPOCH"),EPOCH_MS:p(t=>new z({this:R(t,0),scale:z.MILLIS}),"EPOCH_MS"),GENERATE_SERIES:Ga(),GET_CURRENT_TIME:p(t=>zs.fromArgList(t),"GET_CURRENT_TIME"),GET_BIT:p(t=>new Ee({this:R(t,0),expression:R(t,1),zeroIsMsb:!0}),"GET_BIT"),JARO_WINKLER_SIMILARITY:p(t=>vs.fromArgList(t),"JARO_WINKLER_SIMILARITY"),JSON:p(t=>Jn.fromArgList(t),"JSON"),JSON_EXTRACT_PATH:Os(as),JSON_EXTRACT_STRING:Os(he),LIST_APPEND:p(t=>Ks.fromArgList(t),"LIST_APPEND"),LIST_CONCAT:We,LIST_CONTAINS:p(t=>zt.fromArgList(t),"LIST_CONTAINS"),LIST_COSINE_DISTANCE:p(t=>Bs.fromArgList(t),"LIST_COSINE_DISTANCE"),LIST_DISTANCE:p(t=>Ys.fromArgList(t),"LIST_DISTANCE"),LIST_FILTER:p(t=>ts.fromArgList(t),"LIST_FILTER"),LIST_HAS:p(t=>zt.fromArgList(t),"LIST_HAS"),LIST_HAS_ANY:p(t=>ss.fromArgList(t),"LIST_HAS_ANY"),LIST_PREPEND:ba,LIST_REVERSE_SORT:qa,LIST_SORT:p(t=>cs.fromArgList(t),"LIST_SORT"),LIST_TRANSFORM:p(t=>Vs.fromArgList(t),"LIST_TRANSFORM"),LIST_VALUE:p(t=>new W({expressions:t}),"LIST_VALUE"),MAKE_DATE:p(t=>re.fromArgList(t),"MAKE_DATE"),MAKE_TIME:p(t=>Pn.fromArgList(t),"MAKE_TIME"),MAKE_TIMESTAMP:TE,QUANTILE_CONT:p(t=>Ss.fromArgList(t),"QUANTILE_CONT"),QUANTILE_DISC:p(t=>fs.fromArgList(t),"QUANTILE_DISC"),RANGE:Ga({endExclusive:!0}),REGEXP_EXTRACT:Ue(si),REGEXP_EXTRACT_ALL:Ue(ge),REGEXP_MATCHES:p(t=>Ae.fromArgList(t),"REGEXP_MATCHES"),REGEXP_REPLACE:p(t=>new Es({this:R(t,0),expression:R(t,1),replacement:R(t,2),modifiers:R(t,3),singleReplace:!0}),"REGEXP_REPLACE"),SHA256:p(t=>new we({this:R(t,0),length:a.number(256)}),"SHA256"),STRFTIME:De(_e,{dialect:"duckdb"}),STRING_SPLIT:p(t=>ls.fromArgList(t),"STRING_SPLIT"),STRING_SPLIT_REGEX:p(t=>ps.fromArgList(t),"STRING_SPLIT_REGEX"),STRING_TO_ARRAY:p(t=>ls.fromArgList(t),"STRING_TO_ARRAY"),STRPTIME:De(ui,{dialect:"duckdb"}),STRUCT_PACK:p(t=>ft.fromArgList(t),"STRUCT_PACK"),STR_SPLIT:p(t=>ls.fromArgList(t),"STR_SPLIT"),STR_SPLIT_REGEX:p(t=>ps.fromArgList(t),"STR_SPLIT_REGEX"),TIME_BUCKET:p(t=>se.fromArgList(t),"TIME_BUCKET"),LIST_MAX:p(t=>$s.fromArgList(t),"LIST_MAX"),LIST_MIN:p(t=>Js.fromArgList(t),"LIST_MIN"),CURRENT_LOCALTIMESTAMP:p(t=>tn.fromArgList(t),"CURRENT_LOCALTIMESTAMP"),TODAY:p(t=>Qr.fromArgList(t),"TODAY"),TO_TIMESTAMP:p(t=>z.fromArgList(t),"TO_TIMESTAMP"),UNNEST:p(t=>ie.fromArgList(t),"UNNEST"),VERSION:p(t=>Qs.fromArgList(t),"VERSION"),XOR:ma(Lr)};return delete s.DATE_SUB,delete s.GLOB,s})()}static get FUNCTION_PARSERS(){return(()=>{let s={...F.FUNCTION_PARSERS,...Object.fromEntries(["GROUP_CONCAT","LISTAGG","STRINGAGG"].map(t=>[t,function(){return this.parseStringAgg()}]))};return delete s.DECODE,s})()}static get NO_PAREN_FUNCTION_PARSERS(){return{...F.NO_PAREN_FUNCTION_PARSERS,MAP:p(function(){return this.parseMap()},"MAP"),"@":p(function(){return new Ft({this:this.parseBitwise()})},"@")}}static get ID_VAR_TOKENS(){return new Set([...F.ID_VAR_TOKENS,"straightJoin"])}static get TABLE_ALIAS_TOKENS(){return(()=>{let s=new Set(F.TABLE_ALIAS_TOKENS);return s.delete("semi"),s.delete("anti"),s.add("straightJoin"),s})()}static get PLACEHOLDER_PARSERS(){return{...F.PLACEHOLDER_PARSERS,parameter:function(){return this.match("number")||this.matchSet(this._constructor.ID_VAR_TOKENS)?this.expression(Ar,{this:this.prev?.text}):void 0}}}static get TYPE_CONVERTERS(){return{decimal:wa(18,3),text:()=>l.build("TEXT")??new l({this:"text"})}}static get STATEMENT_PARSERS(){return{...F.STATEMENT_PARSERS,attach:function(){return this.parseAttachDetach()},detach:function(){return this.parseAttachDetach({isAttach:!1})},force:function(){return this.parseForce()},install:function(){return this.parseInstall()},show:function(){return this.parseShow()}}}static get SET_PARSERS(){return{...F.SET_PARSERS,VARIABLE:p(function(){return this.parseSetItemAssignment({kind:"VARIABLE"})},"VARIABLE")}}parseLambda(s={}){let t=this.index;if(!this.matchTextSeq("LAMBDA"))return super.parseLambda(s);let e=this.parseCsv(()=>this.parseLambdaArg());if(!this.match("colon")){this.retreat(t);return}let r=this.replaceLambda(this.parseAssignment(),e);return this.expression(Nt,{this:r,expressions:e,colon:!0})}parseExpression(){if(this.next&&this.next.tokenType==="colon"){let s=this.parseIdVar({tokens:this._constructor.ALIAS_TOKENS});this.match("colon");let t=this.prevComments??[],e=this.parseAssignment();return e instanceof d&&(t=[...t,...e.popComments()??[]]),this.expression(Cs,{comments:t,this:e,alias:s})}return super.parseExpression()}parseTable(s={}){let t,e=[];this.next&&this.next.tokenType==="colon"&&(t=this.parseTableAlias({aliasTokens:s.aliasTokens??this._constructor.TABLE_ALIAS_TOKENS}),this.match("colon"),e=this.prevComments??[]);let r=super.parseTable(s);return r instanceof d&&t instanceof Dt&&(e=[...e,...r.popComments()??[]],t.comments=[...t.popComments()??[],...e],r.setArgKey("alias",t)),r}parseTableSample(s={}){let t=super.parseTableSample(s);return t&&!t.args.method&&(t.args.size?t.setArgKey("method",new P({this:"RESERVOIR"})):t.setArgKey("method",new P({this:"SYSTEM"}))),t}parseBracket(s){let t=super.parseBracket(s);return this.dialect.version.major<=1&&this.dialect.version.minor<=2&&(this.dialect.version.major!==1||this.dialect.version.minor!==2)&&t instanceof q&&t.setArgKey("returnsListForMaps",!0),t}parseMap(){if(this.match("lBrace",{advance:!1}))return this.expression(fe,{this:this.parseBracket()});let s=this.parseWrappedCsv(()=>this.parseAssignment());return this.expression(Se,{keys:R(s,0),values:R(s,1)})}parseStructTypes(s={}){return this.parseFieldDef()}pivotColumnNames(s){return s.length===1?super.pivotColumnNames(s):Ra(s,{dialect:"duckdb"})}parseAttachDetach(s={}){let{isAttach:t=!0}=s,e=p(()=>this.expression(Er,{this:this.parseVar({anyToken:!0}),expression:this.parseField({anyToken:!0})}),"parseAttachOption");this.match("database");let r=this.parseExists({not:t}),i=this.parseAlias(this.parsePrimaryOrVar(),{explicit:!0}),E;return this.match("lParen",{advance:!1})&&(E=this.parseWrappedCsv(e)),t?this.expression(Je,{this:i,exists:r,expressions:E}):this.expression(Ze,{this:i,exists:r})}parseShowDuckdb(s){return this.expression(Qe,{this:s})}parseForce(){return this.match("install")?this.parseInstall({force:!0}):this.parseAsCommand(this.prev)}parseInstall(s={}){return this.expression(je,{this:this.parseIdVar(),from:this.match("from")?this.parseVarOrString():void 0,force:s.force??!1})}parsePrimary(){return this.matchPair("hash","number")?new ur({this:a.number(this.prev?.text||0)}):super.parsePrimary()}};D=yt(So),S(D,10,"NO_PAREN_FUNCTIONS",To,C),S(D,10,"BITWISE",ho,C),S(D,10,"RANGE_PARSERS",uo,C),S(D,10,"EXPONENT",lo,C),S(D,10,"FUNCTIONS_WITH_ALIASED_ARGS",co,C),S(D,10,"SHOW_PARSERS",po,C),S(D,10,"FUNCTIONS",Eo,C),S(D,10,"FUNCTION_PARSERS",oo,C),S(D,10,"NO_PAREN_FUNCTION_PARSERS",ao,C),S(D,10,"ID_VAR_TOKENS",io,C),S(D,10,"TABLE_ALIAS_TOKENS",no,C),S(D,10,"PLACEHOLDER_PARSERS",ro,C),S(D,10,"TYPE_CONVERTERS",eo,C),S(D,10,"STATEMENT_PARSERS",so,C),S(D,10,"SET_PARSERS",to,C),qt(D,C),bt(D,3,C),p(C,"DuckDBParser"),C.MAP_KEYS_ARE_ARBITRARY_EXPRESSIONS=!0;var Xe=C,fo,go,Ao,xo,Ro,mo,Io,No,wo,_o,Oo,Lo,Po,Co,Mo,yo,qo,bo,Do,Go,Fo,Uo,Ho,Bo,_,u=class u extends(Bo=Ct,Ho=[f],Uo=[f],Fo=[f],Go=[f],Do=[f],bo=[f],qo=[f],yo=[f],Mo=[f],Co=[f],Po=[f],Lo=[f],Oo=[f],_o=[f],wo=[f],No=[f],Io=[f],mo=[f],Ro=[f],xo=[f],Ao=[f],go=[f],fo=[f],Bo){static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let s=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(t=>s.delete(t)),s}static get STRUCT_DELIMITER(){return["(",")"]}static get ORIGINAL_TRANSFORMS(){return new Map([...Ct.TRANSFORMS,[Ht,mE],[yi,ia],[br,CE],[Dr,ME],[Gr,yE],[W,As([ra],oa)],[Ks,be("LIST_APPEND")],[Qt,Ia],[kr,function(t){return this.sql(new Qt({this:new W({expressions:t.args.expressions})}))}],[Br,la("LIST_CONCAT")],[ts,x("LIST_FILTER")],[Vr,lE],[Zs,function(t){return t.args.zeroBased?this.sql(new G({this:new Zs({this:t.args.this,expression:t.args.expression}),expression:a.number(1)})):this.func("ARRAY_POSITION",[t.args.this,t.args.expression])}],[Xr,uE],[Fr,Na],[Wr,hE],[Ws,be("LIST_PREPEND",{swapParams:!0})],[$r,x("LIST_SUM")],[bi,function(t){return this.func("LIST",[new Ms({expressions:[t.args.this]})])}],[Un,function(t){return ya.call(this,t,{toString:!1})}],[Hn,function(t){return ya.call(this,t,{toString:!0})}],[wr,function(t){return this.bitwiseOp(t,"&")}],[hs,He],[Ds,Xa],[_r,function(t){return this.bitwiseOp(t,"|")}],[Ts,He],[Or,Xa],[Pe,He],[qr,x("BIT_COUNT")],[jt,function(t){return this.func("OCTET_LENGTH",[t.args.this])}],[Sr,Ea],[gt,function(t){return this.corrSql(t)}],[Bs,x("LIST_COSINE_DISTANCE")],[zs,()=>"CURRENT_TIME"],[te,function(t){return t.args.sysdate?this.sql(new it({this:new P({this:"CURRENT_TIMESTAMP"}),zone:a.string("UTC")})):"CURRENT_TIMESTAMP"}],[jr,function(t){return this.func("current_schemas",[t.args.this??zi()])}],[Qs,x("version")],[zr,function(t){return xs.call(this,t,"this"),"LOCALTIME"}],[un,x("DAYOFMONTH")],[cn,x("DAYOFWEEK")],[ln,x("ISODOW")],[hn,x("DAYOFYEAR")],[Tn,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%a")]):this.func("DAYNAME",[t.args.this])}],[ti,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%b")]):this.func("MONTHNAME",[t.args.this])}],[l,fE],[yn,pE],[es,rt()],[re,PE],[rn,rt()],[ee,Ha],[Cn,ga],[nn,Sa],[En,Ha],[on,rt()],[an,rt()],[Mn,function(t){return`CAST(STRFTIME(${this.sql(t,"this")}, ${Ns.DATEINT_FORMAT}) AS INT)`}],[ns,function(t){return Fe.call(this,t,"DECODE",{replace:!1})}],[qn,function(t){return`CAST(STRPTIME(CAST(${this.sql(t,"this")} AS TEXT), ${Ns.DATEINT_FORMAT}) AS DATE)`}],[ne,function(t){return Fe.call(this,t,"ENCODE",{replace:!1})}],[bn,function(t){return this.sql(new Cr({this:t.args.this,expression:t.args.expression}))}],[Ys,x("LIST_DISTANCE")],[oe,Ba],[Bn,Ba],[Ee,Pa],[Xi,function(t){return La.call(this,t,{withinGroup:!1})}],[ie,x("UNNEST")],[$t,function(t){return this.binary(t,"//")}],[Vn,x("ISINF")],[le,x("ISNAN")],[Xn,function(t){return this.sql(new Y({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("NULL")}))}],[kn,function(t){return this.sql(new Y({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("ARRAY")}))}],[Jr,ka],[ae,ka],[vs,na("JARO_WINKLER_SIMILARITY")],[Kn,x("JSON_EXISTS")],[as,Ua],[Wn,Ya],[$n,gE],[ue,Ya],[bs,function(t){let e=t.args.this;if(e instanceof Dn){let r=new is({expressions:[e.args.this,new Us({this:ta("max_depth"),expression:a.number(2)})]}),i=new st({expressions:[r]}).subquery(),E=t.args.alias;E&&!E.args.this&&E.setArgKey("this",X(`_u_${t.index}`));let c=new bs({this:i,alias:E}),h=new sr({this:c,kind:"cross"});return this.sql(h)}return _a.call(this,t)}],[Ji,function(t){return this.func("BOOL_OR",[Ye(t.args.this)])}],[Zi,function(t){return this.func("BOOL_AND",[Ye(t.args.this)])}],[me,function(t){return ms.call(this,t,1)}],[de,function(t){return ms.call(this,t,2)}],[Ie,function(t){return ms.call(this,t,4)}],[Ne,function(t){return ms.call(this,t,8)}],[Ci,_E],[xn,function(t){return Oa.call(this,t,{sep:" "})}],[zt,function(t){return this.arraycontainsSql(t)}],[ss,function(t){return this.arrayoverlapsSql(t)}],[Yr,function(t){return this.arraydistinctSql(t)}],[vr,function(t){return this.arrayexceptSql(t)}],[$s,x("LIST_MAX")],[Js,x("LIST_MIN")],[jn,function(t){let e=new m({this:"MAP_KEYS",expressions:[t.args.key]});return this.func("ARRAY_CONTAINS",[e,t.args.this])}],[vn,wE],[zn,function(t){return this.func("UNHEX",[this.func("MD5",[t.args.this])])}],[oi,function(t){return ds.call(this,t,"SHA1")}],[Ei,function(t){return ds.call(this,t,"SHA1",{isBinary:!0})}],[we,function(t){return ds.call(this,t,"SHA256")}],[pi,function(t){return ds.call(this,t,"SHA256",{isBinary:!0})}],[An,ua],[Le,Va],[Ss,x("QUANTILE_CONT")],[fs,x("QUANTILE_DISC")],[ir,As([ea])],[mn,Va],[st,As([AE])],[Es,function(t){return this.regexpreplaceSql(t)}],[ii,function(t){return this.regexpcountSql(t)}],[ni,function(t){return this.regexpinstrSql(t)}],[Ae,function(t){return this.regexplikeSql(t)}],[ei,function(t){return this.func("REGEXP_MATCHES",[t.args.this,t.args.expression,a.string("i")])}],[ps,x("STR_SPLIT_REGEX")],[Ce,Ka],[ji,Ka],[rr,function(t){return this.sql(t,"this")}],[qs,function(t){return t.args.this instanceof nr?"TABLE":""}],[li,pa],[hi,function(t){return this.func("EPOCH",[this.func("STRPTIME",[t.args.this,this.formatTime(t)])])}],[ft,SE],[Vs,x("LIST_TRANSFORM")],[_n,rt()],[On,rt()],[Ti,Ta],[Ln,cE],[dn,ha],[In,rt()],[wn,function(t){return this.func("DATE_DIFF",[a.string(t.args.unit),t.args.expression,t.args.this])}],[Nn,rt()],[Si,function(t){return this.sql(new T({this:t.args.this,to:new l({this:"date"})}))}],[fi,fa],[gi,function(t){return this.func("EPOCH",[new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[_e,function(t){return this.func("STRFTIME",[t.args.this,this.formatTime(t)])}],[Ur,EE],[Hr,function(t){return this.sql(Et(t.args.this,l.build("VARIANT",{dialect:"duckdb"})))}],[Oe,x("EPOCH")],[di,function(t){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(t,"this")} AS TEXT), '-', ''), 1, 8) AS INT)`}],[xi,rt()],[Ri,function(t){let r=t.args.unit?.name?.toUpperCase()||"DAY";return this.func("DATE_DIFF",[a.string(r),new T({this:t.args.expression,to:new l({this:"timestamp"})}),new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Oi,function(t){return this.func("EPOCH_US",[Rt(t.args.this)])}],[Li,function(t){return this.func("EPOCH_MS",[Rt(t.args.this)])}],[_i,function(t){return this.sql(new T({this:this.func("EPOCH",[Rt(t.args.this)]),to:new l({this:"bigint"})}))}],[Ni,function(t){return this.func("STRFTIME",[this.func("TO_TIMESTAMP",[t.args.this]),this.formatTime(t)])}],[pn,function(t){return this.func("DATE_TRUNC",[Mt(t),new T({this:t.args.this,to:new l({this:"datetime"})})])}],[z,xE],[wi,function(t){return`CAST(TO_TIMESTAMP(${this.sql(t,"this")}) AS TEXT)`}],[Qn,function(t){return this.func("MAP",[t.args?.keys,t.args?.values])}],[Qi,x("VAR_POP")],[Sn,x("WEEKOFYEAR")],[fn,function(t){return this.sql(new rs({this:new P({this:"ISOYEAR"}),expression:t.args.this}))}],[gn,function(t){return this.sql(new rs({this:new P({this:"ISOYEAR"}),expression:t.args.this}))}],[Ki,qE],[Wi,x("JSON_GROUP_OBJECT")],[$i,x("JSON_GROUP_OBJECT")],[se,x("TIME_BUCKET")],[Rn,oE]])}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([Rr,mr,dr,Ir])}static get TYPE_MAPPING(){return new Map([...Ct.TYPE_MAPPING,["binary","BLOB"],["bpchar","TEXT"],["char","TEXT"],["datetime","TIMESTAMP"],["decfloat","DECIMAL(38, 5)"],["float","REAL"],["jsonb","JSON"],["nchar","TEXT"],["nvarchar","TEXT"],["uint","UINTEGER"],["varbinary","BLOB"],["rowversion","BLOB"],["varchar","TEXT"],["timestampltz","TIMESTAMPTZ"],["timestampntz","TIMESTAMP"],["timestampS","TIMESTAMP_S"],["timestampMs","TIMESTAMP_MS"],["timestampNs","TIMESTAMP_NS"],["bigdecimal","DECIMAL(38, 5)"]])}static get RESERVED_KEYWORDS(){return new Set(["array","analyse","union","all","when","in_p","default","create_p","window","asymmetric","to","else","localtime","from","end_p","select","current_date","foreign","with","grant","session_user","or","except","references","fetch","limit","group_p","leading","into","collate","offset","do","then","localtimestamp","check_p","lateral_p","current_role","where","asc_p","placing","desc_p","user","unique","initially","column","both","some","as","any","only","deferrable","null_p","current_time","true_p","table","case","trailing","variadic","for","on","distinct","false_p","not","constraint","current_timestamp","returning","primary","intersect","having","analyze","current_user","and","cast","symmetric","using","order","current_catalog"])}static get UNWRAPPED_INTERVAL_VALUES(){return new Set([a,w])}static get PROPERTIES_LOCATION(){let s=new Map;return[...Ct.PROPERTIES_LOCATION.keys()].forEach(t=>{s.set(t,"unsupported")}),s.set(fr,"postSchema"),s.set(gr,"postCreate"),s.set(qs,"postAlias"),s.set($e,"postExpression"),s}static get IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS(){return[Ui,Di,Hi,Gi,Bi]}static get ZIPF_TEMPLATE(){return y(`
|
|
1
|
+
import{a as ya}from"../chunk-EO7P6GX2.js";import"../chunk-QON2LPKU.js";import{$d as ys,$m as cn,$n as pe,$r as Ss,$s as Yi,$t as zi,$u as b,Ad as wt,Ai as nt,Ak as Dr,Al as Kr,Am as ee,Ap as fe,Aq as ii,Ar as gi,Av as ra,Bl as Wr,Bm as sn,Bq as ai,Br as fi,Bw as Ra,Ci as jt,Cl as es,Cm as en,Cn as On,Co as Q,Cq as us,Cr as Ai,Ct as qe,Dd as nr,Dj as Ys,Dn as Pn,Do as he,Dq as oi,Dr as xi,Dt as ji,Ef as Sr,Ej as Mr,Ek as ts,El as rs,Em as re,En as Cn,Eo as Xn,Ep as Ae,Eq as me,Er as Ri,Eu as y,Fi as xr,Fk as Gr,Fp as xe,Fq as Ei,Fr as di,Gi as it,Gj as Qt,Gk as Fr,Gn as ae,Go as Te,Gv as na,Gw as da,Hc as Gt,He as pr,Hh as Fs,Hi as j,Hj as at,Hk as Ur,Hl as zs,Hn as yn,Hq as Ne,Hv as ds,Hw as ma,If as Ds,Ij as vs,In as Mn,Io as Vn,Ip as zn,Iv as Ct,Jb as Ze,Jk as Hr,Jo as Kn,Jr as mi,Js as qi,Ke as qs,Ki as _t,Kk as Ut,Kl as te,Km as rn,Kn as qn,Ko as Wn,Kq as Ie,Ku as be,Lj as ks,Ll as $r,Ln as bn,Lq as we,Lr as Ni,Ls as bi,Lv as De,Ma as Nt,Me as cr,Mj as qr,Mq as _e,Mr as Ii,Mu as f,Ni as q,Nj as St,Nn as os,Nq as Le,Nu as ta,Nv as ia,Oe as ct,Oj as gt,Ov as R,Pj as Ft,Pm as nn,Pp as ti,Pv as aa,Qi as Y,Qk as Ht,Ql as ns,Qr as wi,Qu as sa,Rb as je,Rd as ir,Re as bs,Rl as Bt,Rn as Dn,Rr as st,Ru as ea,Rv as oa,Sa as m,Sb as Qe,Si as Rr,Sk as d,Sl as Jr,Sn as oe,Sp as si,Sr as _i,Ss as kt,Sw as Na,Tb as ze,Tf as gr,Tj as F,Tl as Zr,Tm as is,To as Se,Tr as Li,Ts as Di,Tt as Qi,Tv as Ea,Tw as yt,Uc as Cs,Ue as lr,Ui as dr,Uk as W,Um as ne,Uq as pi,Ur as Oi,Us as Gi,Vc as er,Vl as $,Vm as an,Vn as Gn,Vq as Oe,Vr as Pi,Vs as Fi,We as ur,Wi as mr,Wj as Ot,Wl as T,Wm as ie,Wp as ei,Wq as ci,Xj as L,Xk as Br,Xq as li,Xs as Ui,Yc as It,Ye as hr,Yh as Ar,Yj as br,Yk as Yr,Ym as on,Yn as Ee,Yr as Ci,Ys as Hi,Zg as Gs,Zm as En,Zn as Fn,Zq as hs,Zs as Bi,_a as Os,_i as Nr,_j as zt,_m as pn,_n as Es,_v as pa,a as p,ab as $e,ae as C,aj as Ir,an as ln,ar as Ts,as as At,ax as Ia,b as Mt,bc as tr,bo as Un,bp as $n,bw as ca,bx as wa,c as qt,cc as sr,ce as ar,cj as Us,cn as un,d as bt,dj as wr,dn as hn,do as Hn,dp as ps,dr as Pt,ds as ye,dt as vi,du as Vt,dw as Ge,dx as _a,e as S,em as jr,en as Tn,ep as Jn,eu as Kt,ew as la,fm as Yt,fn as Sn,fo as Bn,fp as ge,fw as ua,ge as or,gm as Qr,gn,go as Yn,gr as ui,gt as ki,gv as k,hm as vt,ht as Xi,hu as xt,hw as ha,ib as Zt,ic as Dt,in as fn,ip as Zn,iw as Fe,ix as Be,jb as Ps,jf as B,jj as I,jn as An,jt as Vi,ju as H,jx as La,ke as Ms,kn as xn,kq as cs,kt as Xt,kv as Rs,le as Er,lj as _r,ln as Rn,lt as Ki,lx as Oa,mf as Tr,mh as fr,mj as Hs,ml as Ws,mn as dn,mr as hi,ms as gs,mt as Wi,mw as Ue,nb as Je,ne as l,nj as Lr,nl as $s,nn as mn,nq as tt,nr as Ti,ns as fs,nt as $i,nx as Pa,ob as U,oj as Or,on as Nn,oo as ce,op as jn,os as Me,pj as Pr,po as vn,ps as yi,pt as Ji,pw as Ta,q as K,qj as lt,qt as Zi,qw as Sa,rg as a,rl as Js,rm as zr,ro as le,rw as ga,rx as Ca,s as g,sd as rt,sl as Zs,so as ue,sr as ft,su as J,tl as vr,tn as as,to as kn,tp as Qn,tu as ot,uj as Bs,ul as ss,uw as fa,ux as Wt,vd as rr,vj as Cr,vk as Xs,vl as kr,vm as se,vq as ri,vu as x,vw as Aa,wb as N,wj as v,wl as Xr,wn as In,wq as Re,wr as Si,wt as As,ww as He,xj as yr,xk as Vs,xl as js,xn as wn,xp as z,xq as ls,xr as Pe,xt as xs,yl as Qs,ym as tn,yn as _n,yq as de,zj as Lt,zk as Ks,zl as Vr,zn as Ln,zq as ni,zr as Ce,zs as Mi,zw as xa}from"../chunk-3XSLMNQQ.js";var eE=/:\d{2}.*?[+\-]\d{2}(?::\d{2})?/,Ma={"\\":"\\\\","-":"\\-","^":"\\^","[":"\\[","]":"\\]"},rE="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",nE=123456,ms={"\v":11,"":28,"":29,"":30,"":31},ws={MONDAY:1,TUESDAY:2,WEDNESDAY:3,THURSDAY:4,FRIDAY:5,SATURDAY:6,SUNDAY:7},iE=a.number(32768),aE=y("(ROW_NUMBER() OVER (ORDER BY 1) - 1)"),oE=new Map([[Ie,1],[we,2],[_e,4],[Le,8]]),EE=[Ms,er,Rr,wt,nt];function Jo(n,o,s={}){let{reverse:t=!1}=s;if(o instanceof a&&o.isString){let r=o.args.this??"";for(let i=0;i<Math.min(3,r.length);i++){let E="+/="[i],c=r[i]??"";if(c!==E){let[u,A]=t?[c,E]:[E,c];n=new Ei({this:n,expression:a.string(u),replacement:a.string(A)})}}}return n}p(Jo,"applyBase64AlphabetReplacements");function qa(n,o){let{toString:s=!1}=o,t=n.args.this,e=n.args.alphabet;return t=Jo(t??f(),e,{reverse:!0}),t=new Un({this:t}),s&&(t=new os({this:t})),this.sql(t)}p(qa,"base64DecodeSql");function pE(n){let o=n.args.this,s=n.text("unit").toUpperCase();if(!s||s==="MONTH")return this.func("LAST_DAY",[o]);if(s==="YEAR"){let t=x("EXTRACT","YEAR",o),e=x("MAKE_DATE",t,a.number(12),a.number(31));return this.sql(e)}if(s==="QUARTER"){let t=x("EXTRACT","YEAR",o),e=x("EXTRACT","QUARTER",o),r=new gt({this:e,expression:a.number(3)}),i=x("MAKE_DATE",t,r,a.number(1)),E=x("LAST_DAY",i);return this.sql(E)}if(s==="WEEK"){let t=x("EXTRACT","DAYOFWEEK",o),e=new St({this:new L({this:new F({this:a.number(7),expression:t})}),expression:a.number(7)}),r=new Y({this:e,unit:new C({this:"DAY"})}),i=new I({this:o,expression:r});return this.sql(ot(i,"date"))}return this.unsupported(`Unsupported date part '${s}' in LAST_DAY function`),this.functionFallbackSql(n)}p(pE,"lastDaySql");function We(n){return(n instanceof C||n instanceof a)&&n.name.toUpperCase()==="NANOSECOND"}p(We,"isNanosecondUnit");function Zo(n,o){let s=new T({this:n,to:new l({this:"timestampNs"})}),t=new T({this:o,to:new l({this:"timestampNs"})});return this.sql(new F({this:this.func("EPOCH_NS",[s]),expression:this.func("EPOCH_NS",[t])}))}p(Zo,"handleNanosecondDiff");function cE(n){let o=n.args.this,s=n.args.safe??!1,t=new $({}).when(new Ss({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("ON")),new j({this:!0})).when(new Ss({this:new T({this:o,to:new l({this:"varchar"})})}).eq(a.string("OFF")),new j({this:!1})),e;if(s)e=t.else(x("TRY_CAST",o,l.build("boolean")));else{let r=x("TRY_CAST",o,l.build("float")),i=new Xt({this:x("ISNAN",r),expression:x("ISINF",r)});e=t.when(i,x("ERROR",a.string("TO_BOOLEAN: Non-numeric values NaN and INF are not supported"))).else(new T({this:o,to:new l({this:"boolean"})}))}return this.sql(e)}p(cE,"toBooleanSql");function lE(n){let o=n.args.this,s=this.sql(n,"zone");if(s){o=new T({this:o,to:new l({this:"timestamp"})});let t=new ct({this:o,zone:a.string("UTC")});o=new ct({this:t,zone:s})}return this.sql(new T({this:o,to:new l({this:"date"})}))}p(lE,"dateSql");function uE(n){let o=n.args.unit;if(We(o))return Zo.call(this,n.args.expression??f(),n.args.this??f());let s=new T({this:n.args.this,to:new l({this:"time"})}),t=new T({this:n.args.expression,to:new l({this:"time"})});return this.func("DATE_DIFF",[yt(n),t,s])}p(uE,"timeDiffSql");function Et(n={}){let{cast:o=!0}=n,s=Na({cast:o});return function(t){let e=K(t.getArgKey("unit"),"string",N),r=t.args.expression;if(We(e instanceof N?e:void 0)){r instanceof Y&&(r=r.args.this);let i=new T({this:K(t.args.this,"string",N),to:new l({this:"timestampNs"})});return this.sql(this.func("MAKE_TIMESTAMP_NS",[new I({this:this.func("EPOCH_NS",[i]),expression:K(r,"string",N)})]))}return!r||r instanceof Y?s.call(this,t):(k(r,l.REAL_TYPES)&&t.setArgKey("expression",new T({this:this.func("ROUND",[r]),to:new l({this:"int"})})),s.call(this,t))}}p(Et,"dateDeltaToBinaryIntervalOp");function hE(n){let o=n.args.this,s=n.args.position,t=n.args.expression,e=new W({expressions:[t??f()]}),r=n.args.offset??0;if(!s?.isNumber)return this.unsupported("ARRAY_INSERT can only be transpiled with a literal position"),this.func("ARRAY_INSERT",[o,s,t]);let i=s.toValue();0<i?i-=r:i<0&&(i+=r);let E;if(i===0)E=[e,o??f()];else if(0<i){let c=new q({this:o,expressions:[new B({this:a.number(1),expression:a.number(i)})]}),u=new q({this:o,expressions:[new B({this:a.number(i+1)})]});E=[c,e,u]}else{let c=new z({this:o}),u=new I({this:c,expression:a.number(i)}),A=new I({this:u,expression:a.number(1)}),_=new q({this:o,expressions:[new B({this:a.number(1),expression:u})]}),O=new q({this:o,expressions:[new B({this:A})]});E=[_,e,O]}return this.sql(new Q({this:new at({this:o,expression:f()}),true:f(),false:this.func("LIST_CONCAT",E)}))}p(hE,"arrayInsertSql");function TE(n){let o=n.args.this,s=n.args.position;if(!s?.isNumber)return this.unsupported("ARRAY_REMOVE_AT can only be transpiled with a literal position"),this.func("ARRAY_REMOVE_AT",[o,s]);let t=s.toValue(),e;if(t===0)e=new q({this:o,expressions:[new B({this:a.number(2)})]});else if(0<t){let r=new q({this:o,expressions:[new B({this:a.number(1),expression:a.number(t)})]}),i=new q({this:o,expressions:[new B({this:a.number(t+2)})]});e=this.func("LIST_CONCAT",[r,i])}else if(t===-1){let r=new z({this:o}),i=new I({this:r,expression:a.number(-1)});e=new q({this:o,expressions:[new B({this:a.number(1),expression:i})]})}else{let r=new z({this:o}),i=new I({this:r,expression:a.number(t)}),E=new I({this:i,expression:a.number(2)}),c=new q({this:o,expressions:[new B({this:a.number(1),expression:i})]}),u=new q({this:o,expressions:[new B({this:E})]});e=this.func("LIST_CONCAT",[c,u])}return this.sql(new Q({this:new at({this:o,expression:f()}),true:f(),false:e}))}p(TE,"arrayRemoveAtSql");function SE(n){return n.args.expression&&this.unsupported("DuckDB's ARRAY_SORT does not support a comparator."),this.func("ARRAY_SORT",[n.args.this])}p(SE,"arraySortSql");function ba(n){return new hs({this:m(n,0),asc:new j({this:!1})})}p(ba,"buildSortArrayDesc");function Da(n){return new Zs({this:m(n,1),expression:m(n,0)})}p(Da,"buildArrayPrepend");function Ga(n){return new ie({this:m(n,2),expression:m(n,1),unit:m(n,0)})}p(Ga,"buildDateDiff");function Fa(n={}){let{endExclusive:o=!1}=n;return s=>{s.length===1&&s.unshift(a.number("0"));let t=Ws.fromArgList(s);return t.setArgKey("isEndExclusive",o),t}}p(Fa,"buildGenerateSeries");function gE(n){return n.length===1?new st({this:m(n,0),scale:st.MICROS}):new Ci({year:m(n,0),month:m(n,1),day:m(n,2),hour:m(n,3),min:m(n,4),sec:m(n,5)})}p(gE,"buildMakeTimestamp");function Ua(...n){return function(){return this.parseShowDuckdb(n[0])}}p(Ua,"showParser");function fE(n){let o=n.findAncestor(T,nt);if(o=o instanceof nt?void 0:o,(!n.args.expressions||n.args.expressions.length===0)&&o instanceof T&&k(o.args.to,"map"))return"MAP()";let s=[],t=!n.find(Lt)&&o instanceof T&&[...o.findAll(l)].some(r=>k(r,"struct"));n.args.expressions?.forEach((r,i)=>{let E=r instanceof Lt,c=r.args.this,u=E?r.args.expression:r;if(t)s.push(this.sql(u));else{let A;c instanceof It?A=this.sql(a.string(r.name)):E?A=this.sql(r.args.this):A=this.sql(a.string(`_${i}`)),s.push(`${A}: ${this.sql(u)}`)}});let e=s.join(", ");return t?`ROW(${e})`:`{${e}}`}p(fE,"structSql");function AE(n){if(k(n,"array")){let o=this.expressions(n,{flat:!0}),s=this.expressions(n,{key:"values",flat:!0});return`${o}[${s}]`}if(k(n,["time","timetz","timestamptz"])){let o=n.args.this;return o instanceof N?o.name:o?$e(o):""}return Ct.prototype.dataTypeSql.call(this,n)}p(AE,"dataTypeSql");function xE(n){return`CAST(${this.func("TO_JSON",[n.args.this,n.args.options])} AS TEXT)`}p(xE,"jsonFormatSql");function jo(n,o,s){let t=o*8,e=a.number((2n**BigInt(t)).toString());if(s){let r=a.number((2n**BigInt(t-1)).toString());return b($t.SEQ_SIGNED.copy(),[],{base:n,maxVal:e,half:r})}return b($t.SEQ_UNSIGNED.copy(),[],{base:n,maxVal:e})}p(jo,"buildSeqExpression");function RE(n){if(!(n instanceof nt))return n;let o=n.args.from;return!o||!(o.args.this instanceof wr)||!(o.args.this.args.this instanceof $s)?n:n.transform(s=>{let t=oE.get(s._constructor);return t!==void 0?jo(new Ds({this:H("range")}),t,s.name==="1"):s},{copy:!1})}p(RE,"seqToRangeInGenerator");function Ns(n,o){let s=n.findAncestor(...EE);s&&(!(s instanceof wt||s instanceof nt)||s instanceof wt&&s.parent instanceof jt)&&this.unsupported("SEQ in restricted context is not supported - use CTE or subquery");let t=jo(aE.copy(),o,n.name==="1");return this.sql(t)}p(Ns,"seqSql");function dE(n){let o=n.args.scale,s=o?.toValue(),t=n.args.this,e=n.args.targetType,r=k(e,["timestamp","timestampntz"]);if(s===st.MILLIS.toValue())return this.func("EPOCH_MS",[t]);if(s===st.MICROS.toValue())return this.func("MAKE_TIMESTAMP",[t]);s!==void 0&&s!==st.SECONDS.toValue()&&(t=new lt({this:t,expression:x("POW",a.number(10),o)}));let i=new d({this:"TO_TIMESTAMP",expressions:[t??f()]});return r&&(i=new ct({this:i,zone:a.string("UTC")})),this.sql(i)}p(dE,"unixToTimeSql");var mE=[_t,q,zt,Ot];function Ha(n){let o=oa.call(this,n);return!n.sameParent&&mE.some(s=>n.parent instanceof s)&&(o=this.wrap(o)),o}p(Ha,"arrowJsonExtractSqlDuckDB");function dt(n,o="date"){if(n instanceof a&&n.isString){let s=n.args.this??"",t=o;return o==="date"&&s.includes(":")&&(t=eE.test(s)?"timestamptz":"timestamp"),new T({this:n,to:new l({this:t})})}return n}p(dt,"implicitDatetimeCast");function Qo(n){if(n instanceof C&&"ISOWEEK".includes(n.name.toUpperCase()))return 1;if(n instanceof Tr)return ws[n.name.toUpperCase()]}p(Qo,"weekUnitToDow");function ve(n,o,s={}){let{preserveStartDay:t=!1}=s,e=o===7?1:1-o,r=x("DATE_TRUNC",new C({this:"WEEK"}),n);if(e===0)return r;let i=new Y({this:a.string(e.toString()),unit:new C({this:"DAY"})}),E=new is({this:n,expression:i});if(r.setArgKey("this",E),t){let c=new Y({this:a.string((-e).toString()),unit:new C({this:"DAY"})});return ot(new is({this:r,expression:c}),"date")}return r}p(ve,"buildWeekTruncExpression");function Ba(n){let o=n.args.unit;if(We(o))return Zo.call(this,n.args.this??f(),n.args.expression??f());let s=dt(n.args.this),t=dt(n.args.expression),e=n.args.datePartBoundary,r=Qo(o);return e&&r!==void 0&&s&&t&&(n.setArgKey("unit",a.string("WEEK")),s=ve(s,r),t=ve(t,r)),this.func("DATE_DIFF",[yt(n),t,s])}p(Ba,"dateDiffSql");function Ya(n){let o=n instanceof ce,s=o?"date":"timestamp",t=dt(n.args.start,s),e=dt(n.args.end,s),r=new Ws({start:t,end:e,step:n.args.step});return o&&(r=new T({this:r,to:l.build("ARRAY<DATE>")})),this.sql(r)}p(Ya,"generateDatetimeArraySql");function va(n){let o=n.args.expression instanceof N?n.args.expression:void 0,s=new ps({this:n.args.this,expression:o}),t=n instanceof Se?"ARRAY<STRING>":"ARRAY<JSON>";return this.sql(new T({this:s,to:l.build(t)}))}p(va,"jsonExtractValueArraySql");function et(n){if(n!==void 0)return n instanceof N&&n.type&&!k(n,[...l.TEXT_TYPES,"unknown"])?new T({this:n,to:new l({this:"varchar"})}):n instanceof N?n:a.string(n.toString())}p(et,"castToVarchar");function ke(n){return n&&!k(n,"boolean")?new T({this:n,to:new l({this:"boolean"})}):n}p(ke,"castToBoolean");function Z(n){return k(n,["binary","varbinary","blob"])}p(Z,"isBinary");function ut(n,o){if(Z(n)){let s=l.build("BLOB",{dialect:"duckdb"});o=this.sql(new T({this:o,to:s}))}return o}p(ut,"genWithCastToBlob");function Xe(n){if(!Z(n))return n;let o=n;return n instanceof Sr&&(o=new Ii({this:a.string(n.args.this)})),new T({this:o,to:new l({this:"bit"})})}p(Xe,"castToBit");function ka(n){n.args.this instanceof N&&Z(n.args.this)&&n.setArgKey("this",Xe(n.args.this)),n.args.expression instanceof N&&Z(n.args.expression)&&n.setArgKey("expression",Xe(n.args.expression))}p(ka,"prepareBinaryBitwiseArgs");function Xa(n){let o=n.args.this,s=n.args.expression,t=x("ISODOW",o),e;if(s instanceof a){let i=(s.args.this??"").toUpperCase(),E=Object.keys(ws).find(c=>c.startsWith(i));if(E)e=a.number(ws[E]);else return this.functionFallbackSql(n)}else{let i=new Ss({this:s});e=new $({ifs:Object.entries(ws).map(([E,c])=>new Q({this:this.func("STARTS_WITH",[i.copy(),a.string(E.substring(0,2))]),true:a.number(c)}))})}let r;if(n instanceof ye){let i=xt(e.sub(t).add(6),{copy:!1}),E=new St({this:i,expression:a.number(7)}).add(1);r=new I({this:o,expression:new Y({this:E,unit:new C({this:"DAY"})})})}else{let i=xt(t.sub(e).add(6),{copy:!1}),E=new St({this:i,expression:a.number(7)}).add(1);r=new F({this:o,expression:new Y({this:E,unit:new C({this:"DAY"})})})}return this.sql(new T({this:r,to:new l({this:"date"})}))}p(Xa,"dayNavigationSql");function NE(n){let o=n.args.this;if(o instanceof ur){let s=o.args.max?"ARG_MAX_NULL":"ARG_MIN_NULL";return this.func(s,[o.args.this,o.args.expression])}return this.functionFallbackSql(n)}p(NE,"anyValueSql");function Ye(n){let o="BIT_XOR";n instanceof fs?o="BIT_OR":n instanceof gs&&(o="BIT_AND");let s=n.args.this;return k(s,[...l.REAL_TYPES,...l.TEXT_TYPES])&&(k(s,l.FLOAT_TYPES)&&(s=this.func("ROUND",[s])),s=new T({this:s,to:new l({this:"int"})})),this.func(o,[s])}p(Ye,"bitwiseAggSql");function IE(n){let o=n.split("");if(!o.some(i=>i in ms))return this.sql(a.string(n));let s=[],t=[],e=!1;for(let i of o){let E=i in ms;E!==e&&(0<t.length&&(e?t.forEach(c=>s.push(this.func("CHR",[a.number(ms[c])]))):s.push(this.sql(a.string(t.join(""))))),t=[],e=E),t.push(i)}0<t.length&&(e?t.forEach(i=>s.push(this.func("CHR",[a.number(ms[i])]))):s.push(this.sql(a.string(t.join("")))));let r=s.join(" || ");return s.length===1?r:`(${r})`}p(IE,"literalSqlWithWsChr");function wE(n,o){if(!n)return o;if(n instanceof a&&n.isString){let e=(n.args.this??"").split("").map(r=>Ma[r]??r).join("");return IE.call(this,e)}let s=o;return Object.entries(Ma).forEach(([t,e])=>{s=this.func("REPLACE",[s,this.sql(a.string(t)),this.sql(a.string(e))])}),s}p(wE,"escapeRegexMetachars");function _E(n,o){if(o==="''")return`UPPER(LEFT(${n}, 1)) || LOWER(SUBSTRING(${n}, 2))`;let s=`CONCAT('[', ${o}, ']')`,t=`CONCAT('([', ${o}, ']+|[^', ${o}, ']+)')`;return this.func("ARRAY_TO_STRING",[new $({}).when(`REGEXP_MATCHES(LEFT(${n}, 1), ${s})`,this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])).else(this.func("LIST_TRANSFORM",[this.func("REGEXP_EXTRACT_ALL",[n,t]),"(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END"])),"''"])}p(_E,"buildCapitalizationSql");function LE(n){let o=this.sql(n,"this"),s=n.args.expression;s||(s=a.string(this.dialect._constructor.INITCAP_DEFAULT_DELIMITER_CHARS));let t=this.sql(s),e=wE.call(this,s,t);return _E.call(this,o,e)}p(LE,"initcapSql");function OE(n){return this.sql(new v({this:new vi({this:ke(n.args.this)??n.args.this}),expression:a.number(1)}))}p(OE,"boolxorAggSql");function Va(n){let o=n instanceof Hs?"<<":">>",s=!1,t=n.args.this;t instanceof N&&Z(t)?(s=!0,n.setArgKey("this",ot(t,"bit"))):n.args.requiresInt128&&t instanceof N&&t.replace(ot(t,"int128"));let e=this.binary(n,o);return n.parent instanceof _t&&(e=`(${e})`),s&&(e=this.sql(new T({this:e,to:l.build("BLOB",{dialect:"duckdb"})}))),e}p(Va,"bitshiftSql");function PE(n,o){let s=n.args.decimals;if(!s||n.args.to)return;let t=n.args.this;t instanceof _t&&(t=new L({this:t}));let e=s.isInteger||s.isType([...l.INTEGER_TYPES])?s:new T({this:s,to:new l({this:"int"})}),r=new cs({this:a.number("10"),expression:e}),i=new o({this:new gt({this:t,expression:r})}),E=new lt({this:i,expression:r.copy()});return this.roundSql(new Ne({this:E,decimals:s,castsNonIntegerDecimals:!0}))}p(PE,"scaleRoundingSql");function Ka(n){let o=PE.call(this,n,n._constructor);return o!==void 0?o:this.ceilFloor(n)}p(Ka,"ceilFloor");function Wa(n){let o=n.args.this??f(),s=n.args.expression??f(),t,e,r;n instanceof qe?(t=o,e=s,r="expression"):(t=s,e=o,r="this");let i=e.type;if(!i||typeof i=="string"||i.args.this==="unknown")try{let u=Nt(n.copy(),{dialect:this.dialect}).args[r];i=u instanceof N?u.type:void 0}catch{}(!i||typeof i=="string"||i.args.this==="unknown")&&(i=l.build("double"));let E=new T({this:f(),to:i});return this.sql(new Q({this:new at({this:t.copy(),expression:f()}),true:E,false:e.copy()}))}p(Wa,"regrValSql");function CE(n){let o=n;for(;o instanceof jt||o instanceof Gt;)o=o.args.this??f();if(!(!(o instanceof At)||!o.args.nullOnZeroVariance))return o.setArgKey("nullOnZeroVariance",!1),n}p(CE,"maybeCorrNullToFalse");function yE(n){let o=n.args.year,s=n.args.month,t=n.args.day;if(n.args.allowOverflow){let e=new d({this:"MAKE_DATE",expressions:[o??f(),a.number(1),a.number(1)]});return s&&(e=new I({this:e,expression:new Y({this:new F({this:be(s,_t),expression:a.number(1)}),unit:new C({this:"MONTH"})})})),t&&(e=new I({this:e,expression:new Y({this:new F({this:be(t,_t),expression:a.number(1)}),unit:new C({this:"DAY"})})})),this.sql(new T({this:e,to:new l({this:"date"})}))}return this.func("MAKE_DATE",[o,s,t])}p(yE,"dateFromPartsSql");function mt(n,o){return o?new Ne({this:n,decimals:a.number(0)}):n}p(mt,"roundArg");function ME(n){let o=mt(n.args.this??f(),n.args.roundInput);return this.sql(new Ot({this:new L({this:o})}))}p(ME,"boolnotSql");function qE(n){let o=n.args.roundInput,s=mt(n.args.this??f(),o),t=mt(n.args.expression??f(),o);return this.sql(new L({this:new Vi({this:new L({this:s}),expression:new L({this:t})})}))}p(qE,"boolandSql");function bE(n){let o=n.args.roundInput,s=mt(n.args.this??f(),o),t=mt(n.args.expression??f(),o);return this.sql(new L({this:new Xt({this:new L({this:s}),expression:new L({this:t})})}))}p(bE,"boolorSql");function DE(n){let o=n.args.roundInput,s=n.args.this&&mt(n.args.this,o),t=n.args.expression&&mt(n.args.expression,o);return this.sql(Kt([xt(Vt([s?.copy(),xt(t.not())],{wrap:!1})),xt(Vt([xt(s.not()),t?.copy()],{wrap:!1}))],{wrap:!1}))}p(DE,"xorSql");function Is(n,o,s={}){let{isBinary:t=!1}=s,e=n.args.this;o==="SHA256"&&(n.text("length")||"256")!=="256"&&this.unsupported("DuckDB only supports SHA256 hashing algorithm."),e instanceof N&&e.type&&(!(e.type instanceof N)||e.type.args.this!=="unknown")&&!e.isType(l.TEXT_TYPES)&&!Z(e)&&(e=new T({this:e,to:new l({this:"varchar"})}));let r=this.func(o,[e]);return t?this.func("UNHEX",[r]):r}p(Is,"shaSql");var $a,Ja,Za,ja,Qa,za,to,ht,X=class X extends(to=Wt,za=[g],Qa=[g],ja=[g],Za=[g],Ja=[g],$a=[g],to){static get BYTE_STRINGS(){return[["e'","'"],["E'","'"]]}static get BYTE_STRING_ESCAPES(){return["'","\\"]}static get HEREDOC_STRINGS(){return["$"]}static get ORIGINAL_KEYWORDS(){let s={...Wt.KEYWORDS,"//":"div","**":"dstar","^@":"caretAt","@>":"atGt","<@":"ltAt",ATTACH:"attach",BINARY:"varbinary",BITSTRING:"bit",BPCHAR:"text",CHAR:"text",DATETIME:"timestampntz",DETACH:"detach",FORCE:"force",INSTALL:"install",INT8:"bigint",LOGICAL:"boolean",MACRO:"function",ONLY:"only",PIVOT_WIDER:"pivot",POSITIONAL:"positional",RESET:"command",ROW:"struct",SIGNED:"int",STRING:"text",SUMMARIZE:"summarize",TIMESTAMP:"timestampntz",TIMESTAMP_S:"timestampS",TIMESTAMP_MS:"timestampMs",TIMESTAMP_NS:"timestampNs",TIMESTAMP_US:"timestamp",UBIGINT:"ubigint",UINTEGER:"uint",USMALLINT:"usmallint",UTINYINT:"utinyint",VARCHAR:"text"};return delete s["/*+"],s}static get SINGLE_TOKENS(){return{...Wt.SINGLE_TOKENS,$:"parameter"}}static get COMMANDS(){let s=new Set(Wt.COMMANDS);return s.delete("show"),s}};ht=Mt(to),S(ht,10,"BYTE_STRINGS",za,X),S(ht,10,"BYTE_STRING_ESCAPES",Qa,X),S(ht,10,"HEREDOC_STRINGS",ja,X),S(ht,10,"ORIGINAL_KEYWORDS",Za,X),S(ht,10,"SINGLE_TOKENS",Ja,X),S(ht,10,"COMMANDS",$a,X),qt(ht,X),bt(ht,3,X),p(X,"DuckDBTokenizer"),X.HEREDOC_TAG_IS_IDENTIFIER=!0,X.HEREDOC_STRING_ALTERNATIVE="parameter";var Ve=X,so,eo,ro,no,io,ao,oo,Eo,po,co,lo,uo,ho,To,So,go,D,M=class M extends(go=U,So=[g],To=[g],ho=[g],uo=[g],lo=[g],co=[g],po=[g],Eo=[g],oo=[g],ao=[g],io=[g],no=[g],ro=[g],eo=[g],so=[g],go){static get NO_PAREN_FUNCTIONS(){let s={...U.NO_PAREN_FUNCTIONS};return s.sessionUser=nn,s.currentCatalog=rn,s}static get BITWISE(){return(()=>{let s={...U.BITWISE};return delete s.caret,s})()}static get RANGE_PARSERS(){return{...U.RANGE_PARSERS,damp:Zt(ns),caretAt:Zt(ui),tilde:Zt(ii)}}static get EXPONENT(){return{...U.EXPONENT,caret:cs,dstar:cs}}static get FUNCTIONS_WITH_ALIASED_ARGS(){return new Set([...U.FUNCTIONS_WITH_ALIASED_ARGS,"STRUCT_PACK"])}static get SHOW_PARSERS(){return{TABLES:Ua("TABLES"),"ALL TABLES":Ua("ALL TABLES")}}static get FUNCTIONS(){return(()=>{let s={...U.FUNCTIONS,ANY_VALUE:p(t=>new lr({this:kt.fromArgList(t)}),"ANY_VALUE"),ARRAY_PREPEND:Da,ARRAY_INTERSECT:p(t=>new $r({expressions:t}),"ARRAY_INTERSECT"),ARRAY_REVERSE_SORT:ba,ARRAY_SORT:p(t=>hs.fromArgList(t),"ARRAY_SORT"),BIT_AND:p(t=>gs.fromArgList(t),"BIT_AND"),BIT_OR:p(t=>fs.fromArgList(t),"BIT_OR"),BIT_XOR:p(t=>Me.fromArgList(t),"BIT_XOR"),DATEDIFF:Ga,DATE_DIFF:Ga,DATE_TRUNC:p(t=>Ue([m(t,0),m(t,1)]),"DATE_TRUNC"),DATETRUNC:p(t=>Ue([m(t,0),m(t,1)]),"DATETRUNC"),DECODE:p(t=>new os({this:m(t,0),charset:a.string("utf-8")}),"DECODE"),EDITDIST3:p(t=>fe.fromArgList(t),"EDITDIST3"),ENCODE:p(t=>new oe({this:m(t,0),charset:a.string("utf-8")}),"ENCODE"),EPOCH:p(t=>Ce.fromArgList(t),"EPOCH"),EPOCH_MS:p(t=>new st({this:m(t,0),scale:st.MILLIS}),"EPOCH_MS"),GENERATE_SERIES:Fa(),GET_CURRENT_TIME:p(t=>ee.fromArgList(t),"GET_CURRENT_TIME"),GET_BIT:p(t=>new le({this:m(t,0),expression:m(t,1),zeroIsMsb:!0}),"GET_BIT"),JARO_WINKLER_SIMILARITY:p(t=>Ks.fromArgList(t),"JARO_WINKLER_SIMILARITY"),JSON:p(t=>jn.fromArgList(t),"JSON"),JSON_EXTRACT_PATH:Ps(ps),JSON_EXTRACT_STRING:Ps(ge),LIST_APPEND:p(t=>Js.fromArgList(t),"LIST_APPEND"),LIST_CONCAT:Je,LIST_CONTAINS:p(t=>es.fromArgList(t),"LIST_CONTAINS"),LIST_COSINE_DISTANCE:p(t=>Xs.fromArgList(t),"LIST_COSINE_DISTANCE"),LIST_DISTANCE:p(t=>Vs.fromArgList(t),"LIST_DISTANCE"),LIST_FILTER:p(t=>rs.fromArgList(t),"LIST_FILTER"),LIST_HAS:p(t=>es.fromArgList(t),"LIST_HAS"),LIST_HAS_ANY:p(t=>ns.fromArgList(t),"LIST_HAS_ANY"),LIST_PREPEND:Da,LIST_REVERSE_SORT:ba,LIST_SORT:p(t=>hs.fromArgList(t),"LIST_SORT"),LIST_TRANSFORM:p(t=>Ht.fromArgList(t),"LIST_TRANSFORM"),LIST_VALUE:p(t=>new W({expressions:t}),"LIST_VALUE"),MAKE_DATE:p(t=>ae.fromArgList(t),"MAKE_DATE"),MAKE_TIME:p(t=>yn.fromArgList(t),"MAKE_TIME"),MAKE_TIMESTAMP:gE,QUANTILE_CONT:p(t=>As.fromArgList(t),"QUANTILE_CONT"),QUANTILE_DISC:p(t=>xs.fromArgList(t),"QUANTILE_DISC"),RANGE:Fa({endExclusive:!0}),REGEXP_EXTRACT:Be(ri),REGEXP_EXTRACT_ALL:Be(Re),REGEXP_MATCHES:p(t=>de.fromArgList(t),"REGEXP_MATCHES"),REGEXP_REPLACE:p(t=>new ls({this:m(t,0),expression:m(t,1),replacement:m(t,2),modifiers:m(t,3),singleReplace:!0}),"REGEXP_REPLACE"),SHA256:p(t=>new Oe({this:m(t,0),length:a.number(256)}),"SHA256"),STRFTIME:Fe(Pe,{dialect:"duckdb"}),STRING_SPLIT:p(t=>Ts.fromArgList(t),"STRING_SPLIT"),STRING_SPLIT_REGEX:p(t=>us.fromArgList(t),"STRING_SPLIT_REGEX"),STRING_TO_ARRAY:p(t=>Ts.fromArgList(t),"STRING_TO_ARRAY"),STRPTIME:Fe(hi,{dialect:"duckdb"}),STRUCT_PACK:p(t=>ft.fromArgList(t),"STRUCT_PACK"),STR_SPLIT:p(t=>Ts.fromArgList(t),"STR_SPLIT"),STR_SPLIT_REGEX:p(t=>us.fromArgList(t),"STR_SPLIT_REGEX"),TIME_BUCKET:p(t=>ne.fromArgList(t),"TIME_BUCKET"),LIST_MAX:p(t=>js.fromArgList(t),"LIST_MAX"),LIST_MIN:p(t=>Qs.fromArgList(t),"LIST_MIN"),CURRENT_LOCALTIMESTAMP:p(t=>en.fromArgList(t),"CURRENT_LOCALTIMESTAMP"),TODAY:p(t=>tn.fromArgList(t),"TODAY"),TO_TIMESTAMP:p(t=>st.fromArgList(t),"TO_TIMESTAMP"),UNNEST:p(t=>Ee.fromArgList(t),"UNNEST"),VERSION:p(t=>se.fromArgList(t),"VERSION"),XOR:ma(Pr)};return delete s.DATE_SUB,delete s.GLOB,s})()}static get FUNCTION_PARSERS(){return(()=>{let s={...U.FUNCTION_PARSERS,...Object.fromEntries(["GROUP_CONCAT","LISTAGG","STRINGAGG"].map(t=>[t,function(){return this.parseStringAgg()}]))};return delete s.DECODE,s})()}static get NO_PAREN_FUNCTION_PARSERS(){return{...U.NO_PAREN_FUNCTION_PARSERS,MAP:p(function(){return this.parseMap()},"MAP"),"@":p(function(){return new Ut({this:this.parseBitwise()})},"@")}}static get ID_VAR_TOKENS(){return new Set([...U.ID_VAR_TOKENS,"straightJoin"])}static get TABLE_ALIAS_TOKENS(){return(()=>{let s=new Set(U.TABLE_ALIAS_TOKENS);return s.delete("semi"),s.delete("anti"),s.add("straightJoin"),s})()}static get PLACEHOLDER_PARSERS(){return{...U.PLACEHOLDER_PARSERS,parameter:function(){return this.match("number")||this.matchSet(this._constructor.ID_VAR_TOKENS)?this.expression(xr,{this:this.prev?.text}):void 0}}}static get TYPE_CONVERTERS(){return{decimal:_a(18,3),text:()=>l.build("text")??new l({this:"text"})}}static get STATEMENT_PARSERS(){return{...U.STATEMENT_PARSERS,attach:function(){return this.parseAttachDetach()},detach:function(){return this.parseAttachDetach({isAttach:!1})},force:function(){return this.parseForce()},install:function(){return this.parseInstall()},show:function(){return this.parseShow()}}}static get SET_PARSERS(){return{...U.SET_PARSERS,VARIABLE:p(function(){return this.parseSetItemAssignment({kind:"VARIABLE"})},"VARIABLE")}}parseLambda(s={}){let t=this.index;if(!this.matchTextSeq("LAMBDA"))return super.parseLambda(s);let e=this.parseCsv(()=>this.parseLambdaArg());if(!this.match("colon")){this.retreat(t);return}let r=this.replaceLambda(this.parseAssignment(),e);return this.expression(rt,{this:r,expressions:e,colon:!0})}parseExpression(){if(this.next&&this.next.tokenType==="colon"){let s=this.parseIdVar({tokens:this._constructor.ALIAS_TOKENS});this.match("colon");let t=this.prevComments??[],e=this.parseAssignment();return e instanceof N&&(t=[...t,...e.popComments()??[]]),this.expression(qs,{comments:t,this:e,alias:s})}return super.parseExpression()}parseTable(s={}){let t,e=[];this.next&&this.next.tokenType==="colon"&&(t=this.parseTableAlias({aliasTokens:s.aliasTokens??this._constructor.TABLE_ALIAS_TOKENS}),this.match("colon"),e=this.prevComments??[]);let r=super.parseTable(s);return r instanceof N&&t instanceof Dt&&(e=[...e,...r.popComments()??[]],t.comments=[...t.popComments()??[],...e],r.setArgKey("alias",t)),r}parseTableSample(s={}){let t=super.parseTableSample(s);return t&&!t.args.method&&(t.args.size?t.setArgKey("method",new C({this:"RESERVOIR"})):t.setArgKey("method",new C({this:"SYSTEM"}))),t}parseBracket(s){let t=super.parseBracket(s);return this.dialect.version.major<=1&&this.dialect.version.minor<=2&&(this.dialect.version.major!==1||this.dialect.version.minor!==2)&&t instanceof q&&t.setArgKey("returnsListForMaps",!0),t}parseMap(){if(this.match("lBrace",{advance:!1}))return this.expression(xe,{this:this.parseBracket()});let s=this.parseWrappedCsv(()=>this.parseAssignment());return this.expression(Ae,{keys:m(s,0),values:m(s,1)})}parseStructTypes(s={}){return this.parseFieldDef()}pivotColumnNames(s){return s.length===1?super.pivotColumnNames(s):da(s,{dialect:"duckdb"})}parseAttachDetach(s={}){let{isAttach:t=!0}=s,e=p(()=>this.expression(pr,{this:this.parseVar({anyToken:!0}),expression:this.parseField({anyToken:!0})}),"parseAttachOption");this.match("database");let r=this.parseExists({not:t}),i=this.parseAlias(this.parsePrimaryOrVar(),{explicit:!0}),E;return this.match("lParen",{advance:!1})&&(E=this.parseWrappedCsv(e)),t?this.expression(je,{this:i,exists:r,expressions:E}):this.expression(Qe,{this:i,exists:r})}parseShowDuckdb(s){let t=this.match("from")?this.parseTable({schema:!0}):void 0;return this.expression(tr,{this:s,from:t})}parseForce(){return this.match("install")?this.parseInstall({force:!0}):this.parseAsCommand(this.prev)}parseInstall(s={}){return this.expression(ze,{this:this.parseIdVar(),from:this.match("from")?this.parseVarOrString():void 0,force:s.force??!1})}parsePrimary(){return this.matchPair("hash","number")?new hr({this:a.number(this.prev?.text||0)}):super.parsePrimary()}};D=Mt(go),S(D,10,"NO_PAREN_FUNCTIONS",So,M),S(D,10,"BITWISE",To,M),S(D,10,"RANGE_PARSERS",ho,M),S(D,10,"EXPONENT",uo,M),S(D,10,"FUNCTIONS_WITH_ALIASED_ARGS",lo,M),S(D,10,"SHOW_PARSERS",co,M),S(D,10,"FUNCTIONS",po,M),S(D,10,"FUNCTION_PARSERS",Eo,M),S(D,10,"NO_PAREN_FUNCTION_PARSERS",oo,M),S(D,10,"ID_VAR_TOKENS",ao,M),S(D,10,"TABLE_ALIAS_TOKENS",io,M),S(D,10,"PLACEHOLDER_PARSERS",no,M),S(D,10,"TYPE_CONVERTERS",ro,M),S(D,10,"STATEMENT_PARSERS",eo,M),S(D,10,"SET_PARSERS",so,M),qt(D,M),bt(D,3,M),p(M,"DuckDBParser"),M.MAP_KEYS_ARE_ARBITRARY_EXPRESSIONS=!0;var Ke=M,fo,Ao,xo,Ro,mo,No,Io,wo,_o,Lo,Oo,Po,Co,yo,Mo,qo,bo,Do,Go,Fo,Uo,Ho,Bo,Yo,vo,w,h=class h extends(vo=Ct,Yo=[g],Bo=[g],Ho=[g],Uo=[g],Fo=[g],Go=[g],Do=[g],bo=[g],qo=[g],Mo=[g],yo=[g],Co=[g],Po=[g],Oo=[g],Lo=[g],_o=[g],wo=[g],Io=[g],No=[g],mo=[g],Ro=[g],xo=[g],Ao=[g],fo=[g],vo){static get STRTOK_TEMPLATE(){return y(`
|
|
2
|
+
CASE
|
|
3
|
+
WHEN :delimiter = '' AND :string = '' THEN NULL
|
|
4
|
+
WHEN :delimiter = '' AND :partIndex = 1 THEN :string
|
|
5
|
+
WHEN :delimiter = '' THEN NULL
|
|
6
|
+
WHEN :partIndex < 0 THEN NULL
|
|
7
|
+
WHEN :string IS NULL OR :delimiter IS NULL OR :partIndex IS NULL THEN NULL
|
|
8
|
+
ELSE :baseFunc
|
|
9
|
+
END
|
|
10
|
+
`)}static get AFTER_HAVING_MODIFIER_TRANSFORMS(){let s=new Map(super.AFTER_HAVING_MODIFIER_TRANSFORMS);return["cluster","distribute","sort"].forEach(t=>s.delete(t)),s}static get STRUCT_DELIMITER(){return["(",")"]}static get ORIGINAL_TRANSFORMS(){return new Map([...Ct.TRANSFORMS,[kt,NE],[qi,aa],[Gr,ME],[Fr,qE],[Ur,bE],[W,Rs([na],Ea)],[Js,Ge("LIST_APPEND")],[ss,Ia],[Wr,function(t){return this.sql(new ss({this:new W({expressions:t.args.expressions})}))}],[vr,ua("LIST_CONCAT")],[rs,R("LIST_FILTER")],[Vr,hE],[zs,function(t){return t.args.zeroBased?this.sql(new F({this:new zs({this:t.args.this,expression:t.args.expression}),expression:a.number(1)})):this.func("ARRAY_POSITION",[t.args.this,t.args.expression])}],[Kr,TE],[Hr,wa],[Jr,SE],[Zs,Ge("LIST_PREPEND",{swapParams:!0})],[Zr,R("LIST_SUM")],[Bn,function(t){return qa.call(this,t,{toString:!1})}],[Yn,function(t){return qa.call(this,t,{toString:!0})}],[_r,function(t){return this.bitwiseOp(t,"&")}],[gs,Ye],[Hs,Va],[Lr,function(t){return this.bitwiseOp(t,"|")}],[fs,Ye],[Or,Va],[Me,Ye],[Dr,R("BIT_COUNT")],[ts,function(t){return this.func("OCTET_LENGTH",[t.args.this])}],[gr,pa],[At,function(t){return this.corrSql(t)}],[Xs,R("LIST_COSINE_DISTANCE")],[ee,()=>"CURRENT_TIME"],[re,function(t){return t.args.sysdate?this.sql(new ct({this:new C({this:"CURRENT_TIMESTAMP"}),zone:a.string("UTC")})):"CURRENT_TIMESTAMP"}],[zr,function(t){return this.func("current_schemas",[t.args.this??ta()])}],[se,R("version")],[sn,function(t){return ds.call(this,t,"this"),"LOCALTIME"}],[Tn,R("DAYOFMONTH")],[un,R("DAYOFWEEK")],[hn,R("ISODOW")],[Sn,R("DAYOFYEAR")],[gn,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%a")]):this.func("DAYNAME",[t.args.this])}],[ei,function(t){return t.args.abbreviated?this.func("STRFTIME",[t.args.this,a.string("%b")]):this.func("MONTHNAME",[t.args.this])}],[l,AE],[bn,lE],[is,Et()],[ae,yE],[an,Et()],[ie,Ba],[Mn,Aa],[on,ga],[cn,Ba],[pn,Et()],[En,Et()],[qn,function(t){return`CAST(STRFTIME(${this.sql(t,"this")}, ${_s.DATEINT_FORMAT}) AS INT)`}],[os,function(t){return He.call(this,t,"DECODE",{replace:!1})}],[Dn,function(t){return`CAST(STRPTIME(CAST(${this.sql(t,"this")} AS TEXT), ${_s.DATEINT_FORMAT}) AS DATE)`}],[oe,function(t){return He.call(this,t,"ENCODE",{replace:!1})}],[Gn,function(t){return this.sql(new yr({this:t.args.this,expression:t.args.expression}))}],[Vs,R("LIST_DISTANCE")],[ce,Ya],[vn,Ya],[le,Ca],[Xi,function(t){return Pa.call(this,t,{withinGroup:!1})}],[Ee,R("UNNEST")],[Gs,function(){return""}],[Qt,function(t){return this.binary(t,"//")}],[Vn,R("ISINF")],[Te,R("ISNAN")],[Kn,function(t){return this.sql(new v({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("NULL")}))}],[Wn,function(t){return this.sql(new v({this:this.func("JSON_TYPE",[t.args.this]),expression:a.string("ARRAY")}))}],[jr,Ka],[pe,Ka],[Ks,ia("JARO_WINKLER_SIMILARITY")],[$n,R("JSON_EXISTS")],[ps,Ha],[Jn,va],[Zn,xE],[Se,va],[Us,function(t){let e=t.args.this;if(e instanceof Fn){let r=new Es({expressions:[e.args.this,new vs({this:sa("max_depth"),expression:a.number(2)})]}),i=new nt({expressions:[r]}).subquery(),E=t.args.alias;E&&!E.args.this&&E.setArgKey("this",H(`_u_${t.index}`));let c=new Us({this:i,alias:E}),u=new rr({this:c,kind:"cross"});return this.sql(u)}return La.call(this,t)}],[Ji,function(t){return this.func("BOOL_OR",[ke(t.args.this)])}],[Zi,function(t){return this.func("BOOL_AND",[ke(t.args.this)])}],[Ie,function(t){return Ns.call(this,t,1)}],[we,function(t){return Ns.call(this,t,2)}],[_e,function(t){return Ns.call(this,t,4)}],[Le,function(t){return Ns.call(this,t,8)}],[yi,OE],[dn,function(t){return Oa.call(this,t,{sep:" "})}],[es,function(t){return this.arraycontainsSql(t)}],[ns,function(t){return this.arrayoverlapsSql(t)}],[kr,function(t){return this.arraydistinctSql(t)}],[Xr,function(t){return this.arrayexceptSql(t)}],[js,R("LIST_MAX")],[Qs,R("LIST_MIN")],[zn,function(t){let e=new d({this:"MAP_KEYS",expressions:[t.args.key]});return this.func("ARRAY_CONTAINS",[e,t.args.this])}],[Xn,LE],[si,function(t){return this.func("UNHEX",[this.func("MD5",[t.args.this])])}],[pi,function(t){return Is.call(this,t,"SHA1")}],[ci,function(t){return Is.call(this,t,"SHA1",{isBinary:!0})}],[Oe,function(t){return Is.call(this,t,"SHA256")}],[li,function(t){return Is.call(this,t,"SHA256",{isBinary:!0})}],[Rn,ha],[ye,Xa],[As,R("QUANTILE_CONT")],[xs,R("QUANTILE_DISC")],[or,Rs([ra])],[Nn,Xa],[nt,Rs([RE])],[ls,function(t){return this.regexpreplaceSql(t)}],[oi,function(t){return this.regexpcountSql(t)}],[ai,function(t){return this.regexpinstrSql(t)}],[de,function(t){return this.regexplikeSql(t)}],[ni,function(t){return this.func("REGEXP_MATCHES",[t.args.this,t.args.expression,a.string("i")])}],[us,R("STR_SPLIT_REGEX")],[qe,Wa],[ji,Wa],[ir,function(t){return this.sql(t,"this")}],[Fs,function(t){return t.args.this instanceof ar?"TABLE":""}],[Ti,function(t){return this.func("EPOCH",[this.func("STRPTIME",[t.args.this,this.formatTime(t)])])}],[ft,fE],[Ht,R("LIST_TRANSFORM")],[On,Et()],[Pn,Et()],[Si,Sa],[Cn,uE],[In,Ta],[wn,Et()],[Ln,function(t){return this.func("DATE_DIFF",[a.string(t.args.unit),t.args.expression,t.args.this])}],[_n,Et()],[gi,function(t){return this.sql(new T({this:t.args.this,to:new l({this:"date"})}))}],[fi,fa],[Ai,function(t){return this.func("EPOCH",[new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Pe,function(t){return this.func("STRFTIME",[t.args.this,this.formatTime(t)])}],[Br,cE],[Yr,function(t){return this.sql(ot(t.args.this,l.build("VARIANT",{dialect:"duckdb"})))}],[Ce,R("EPOCH")],[Ni,function(t){return`CAST(SUBSTR(REPLACE(CAST(${this.sql(t,"this")} AS TEXT), '-', ''), 1, 8) AS INT)`}],[Ri,Et()],[di,function(t){let r=t.args.unit?.name?.toUpperCase()||"DAY";return this.func("DATE_DIFF",[a.string(r),new T({this:t.args.expression,to:new l({this:"timestamp"})}),new T({this:t.args.this,to:new l({this:"timestamp"})})])}],[Oi,function(t){return this.func("EPOCH_US",[dt(t.args.this)])}],[Pi,function(t){return this.func("EPOCH_MS",[dt(t.args.this)])}],[Li,function(t){return this.sql(new T({this:this.func("EPOCH",[dt(t.args.this)]),to:new l({this:"bigint"})}))}],[wi,function(t){return this.func("STRFTIME",[this.func("TO_TIMESTAMP",[t.args.this]),this.formatTime(t)])}],[ln,function(t){return this.func("DATE_TRUNC",[yt(t),new T({this:t.args.this,to:new l({this:"datetime"})})])}],[st,dE],[_i,function(t){return`CAST(TO_TIMESTAMP(${this.sql(t,"this")}) AS TEXT)`}],[ti,function(t){return this.func("MAP",[t.args?.keys,t.args?.values])}],[Qi,R("VAR_POP")],[fn,R("WEEKOFYEAR")],[An,function(t){return this.sql(new as({this:new C({this:"ISOYEAR"}),expression:t.args.this}))}],[xn,function(t){return this.sql(new as({this:new C({this:"ISOYEAR"}),expression:t.args.this}))}],[Ki,DE],[Wi,R("JSON_GROUP_OBJECT")],[$i,R("JSON_GROUP_OBJECT")],[ne,R("TIME_BUCKET")],[mn,pE]])}static get SUPPORTED_JSON_PATH_PARTS(){return new Set([dr,mr,Nr,Ir])}static get TYPE_MAPPING(){return new Map([...Ct.TYPE_MAPPING,["binary","BLOB"],["bpchar","TEXT"],["char","TEXT"],["datetime","TIMESTAMP"],["decfloat","DECIMAL(38, 5)"],["float","REAL"],["jsonb","JSON"],["nchar","TEXT"],["nvarchar","TEXT"],["uint","UINTEGER"],["varbinary","BLOB"],["rowversion","BLOB"],["varchar","TEXT"],["timestampltz","TIMESTAMPTZ"],["timestampntz","TIMESTAMP"],["timestampS","TIMESTAMP_S"],["timestampMs","TIMESTAMP_MS"],["timestampNs","TIMESTAMP_NS"],["bigdecimal","DECIMAL(38, 5)"]])}static get RESERVED_KEYWORDS(){return new Set(["array","analyse","union","all","when","in_p","default","create_p","window","asymmetric","to","else","localtime","from","end_p","select","current_date","foreign","with","grant","session_user","or","except","references","fetch","limit","group_p","leading","into","collate","offset","do","then","localtimestamp","check_p","lateral_p","current_role","where","asc_p","placing","desc_p","user","unique","initially","column","both","some","as","any","only","deferrable","null_p","current_time","true_p","table","case","trailing","variadic","for","on","distinct","false_p","not","constraint","current_timestamp","returning","primary","intersect","having","analyze","current_user","and","cast","symmetric","using","order","current_catalog"])}static get UNWRAPPED_INTERVAL_VALUES(){return new Set([a,L])}static get PROPERTIES_LOCATION(){let s=new Map;return[...Ct.PROPERTIES_LOCATION.keys()].forEach(t=>{s.set(t,"unsupported")}),s.set(fr,"postSchema"),s.set(Ar,"postCreate"),s.set(Fs,"postAlias"),s.set(Ze,"postExpression"),s.set(Gs,"postCreate"),s}static get IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS(){return[Ui,Di,Hi,Gi,Bi]}static get ZIPF_TEMPLATE(){return y(`
|
|
2
11
|
WITH rand AS (SELECT :randomExpr AS r),
|
|
3
12
|
weights AS (
|
|
4
13
|
SELECT i, 1.0 / POWER(i, :s) AS w
|
|
@@ -39,7 +48,7 @@ import{a as Ca}from"../chunk-3OVM5ZRR.js";import"../chunk-KNRQDMQ7.js";import{$d
|
|
|
39
48
|
`)}static get RANDSTR_TEMPLATE(){return y(`
|
|
40
49
|
SELECT LISTAGG(
|
|
41
50
|
SUBSTRING(
|
|
42
|
-
'${
|
|
51
|
+
'${rE}',
|
|
43
52
|
1 + CAST(FLOOR(random_value * 62) AS INT),
|
|
44
53
|
1
|
|
45
54
|
),
|
|
@@ -82,7 +91,7 @@ import{a as Ca}from"../chunk-3OVM5ZRR.js";import"../chunk-KNRQDMQ7.js";import{$d
|
|
|
82
91
|
WHEN :allEmptyCheck THEN [:emptyStruct]
|
|
83
92
|
ELSE LIST_TRANSFORM(RANGE(0, :maxLen), __i -> :transformStruct)
|
|
84
93
|
END
|
|
85
|
-
`)}timeSliceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.unit,i=s.text("kind").toUpperCase(),E=new B({this:e,unit:r}),c=this.func("time_bucket",[E,t]);if(i!=="END")return this.sql(c);let h=new I({this:c,expression:E.copy()});return t?.isType("date")?this.sql(new T({this:h,to:new l({this:"date"})})):this.sql(h)}bitmapBucketNumberSql(s){let t=s.args.this,e=new I({this:new w({this:new $t({this:new w({this:new G({this:t,expression:a.number(1)})}),expression:a.number(32768)})}),expression:a.number(1)}),r=new $t({this:t,expression:a.number(32768)});return this.sql(new $({}).when(new Fs({this:t,expression:a.number(0)}),e).else(r))}bitmapBitPositionSql(s){let t=s.args.this;return this.sql(new Tt({this:new w({this:new et({this:new Fs({this:t,expression:a.number(0)}),true:new G({this:t,expression:a.number(1)}),false:new Ft({this:t})})}),expression:rE}))}bitmapConstructAggSql(s){let t=s.args.this;return`(${this.sql(b(this._constructor.BITMAP_CONSTRUCT_AGG_TEMPLATE.copy(),[],{arg:t}))})`}nthValueSql(s){return(s.args.fromFirst??!0)||this.unsupported("DuckDB's NTH_VALUE doesn't support starting from the end"),this.functionFallbackSql(s)}randstrSql(s){let t=s.args.this,e=s.args.generator,r;return e?e instanceof Q?r=e.args.this??e:r=e:r=a.number(eE),`(${this.sql(b(this._constructor.RANDSTR_TEMPLATE.copy(),[],{seed:r,length:t}))})`}zipfSql(s){let t=s.args.this,e=s.args.elementcount,r=s.args.gen,i;return r instanceof Q?i=new Q({}):i=new at({this:new w({this:new Tt({this:new Ft({this:new m({this:"HASH",expressions:[(r??g()).copy()]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")}),`(${this.sql(b(this._constructor.ZIPF_TEMPLATE.copy(),[],{s:t,n:e,randomExpr:i}))})`}toBinarySql(s){let t=s.args.this,e=K(s.args.format,d),r=s.args.safe,i=J(s);if(!e&&!i){let h=r?"TRY_TO_BINARY":"TO_BINARY";return this.func(h,[t])}let E=e?.name?.toUpperCase()??"HEX",c;if(E==="UTF-8"||E==="UTF8")c=this.func("ENCODE",[t]);else if(E==="BASE64")c=this.func("FROM_BASE64",[t]);else if(E==="HEX")c=this.func("UNHEX",[t]);else{if(r)return this.sql(g());this.unsupported(`format ${E} is not supported`),c=this.func("TO_BINARY",[t])}return r?`TRY(${c})`:c}greatestLeastSql(s){let t=[s.args.this,...s.args.expressions??[]],e=this.functionFallbackSql(s);if(s.args.ignoreNulls)return this.sql(e);let r=new $({}).when(gs(t.map(i=>(i??g()).is(g())),{copy:!1}),g());return r.setArgKey("default",e),this.sql(r)}generatorSql(s){let t=s.args.rowcount;return s.args.timelimit&&this.unsupported("GENERATOR TIMELIMIT parameter is not supported in DuckDB"),t?this.func("range",[t]):(this.unsupported("GENERATOR without ROWCOUNT is not supported in DuckDB"),this.func("range",[a.number(0)]))}greatestSql(s){return this.greatestLeastSql(s)}leastSql(s){return this.greatestLeastSql(s)}lambdaSql(s,t={}){let e=t.arrowSep??"->",r=t.wrap??!0,i="";s.args.colon&&(i="LAMBDA ",e=":",r=!1);let E=super.lambdaSql(s,{arrowSep:e,wrap:r});return`${i}${E}`}sortArraySql(s){let t=s.args.this,e=s.args.asc,r=s.args.nullsFirst;if(!(e instanceof Z)&&!(r instanceof Z))return this.func("LIST_SORT",[t,e,r]);let i=r instanceof Z&&r.args.this===!0,E=i?a.string("NULLS FIRST"):void 0;if(!(e instanceof Z))return this.func("LIST_SORT",[t,e,E]);let c=e.args.this===!1;return!c&&!i?this.func("LIST_SORT",[t]):i?this.func("LIST_SORT",[t,a.string(c?"DESC":"ASC"),a.string("NULLS FIRST")]):this.func("ARRAY_REVERSE_SORT",[t])}showSql(s){return`SHOW ${s.name}`}installSql(s){let t=s.args.force?"FORCE ":"",e=this.sql(s,"this"),r=s.args.from?` FROM ${s.args.from}`:"";return`${t}INSTALL ${e}${r}`}approxTopKSql(s){return this.unsupported("APPROX_TOP_K cannot be transpiled to DuckDB due to incompatible return types. "),this.functionFallbackSql(s)}fromIso8601TimestampSql(s){return this.sql(new T({this:s.args.this,to:new l({this:"timestamptz"})}))}strToTimeSql(s){let t=s.args.targetType,e=t&&["timestampltz","timestamptz"].includes(t.args.this);if(s.args.safe){let i=this.formatTime(s),E=e?"timestamptz":"timestamp";return this.sql(new T({this:this.func("TRY_STRPTIME",[s.args.this,i]),to:new l({this:E})}))}let r=xa.call(this,s);return e?this.sql(new T({this:r,to:new l({this:"timestamptz"})})):r}strToDateSql(s){let t=this.formatTime(s),e=s.args.safe?"TRY_STRPTIME":"STRPTIME";return this.sql(new T({this:this.func(e,[s.args.this,t]),to:new l({this:"date"})}))}tsOrDsToTimeSql(s){let t=s.args.this,e=this.formatTime(s),r=s.args.safe,i=l.build("TIME",{dialect:"duckdb"}),E=r?Yi:T;if(e){let c=r?"TRY_STRPTIME":"STRPTIME",h=new m({this:c,expressions:[t??g(),e]});return this.sql(new E({this:h,to:i}))}return t instanceof mi||t?.isType("time")?this.sql(t??g()):this.sql(new E({this:t,to:i}))}validateRegexpFlags(s,t){if(!(s instanceof d))return;if(!s.isString){this.unsupported("Non-literal regexp flags are not fully supported in DuckDB");return}let e=s.name??"",r=new Set(t),i=[...new Set(e)].filter(c=>!r.has(c));return 0<i.length&&this.unsupported(`Regexp flags ${JSON.stringify(i.sort())} are not supported in this context`),[...e].filter(c=>r.has(c)).join("")||void 0}regexplikeSql(s){let t=s.args.this,e=s.args.expression,r=s.args.flag;if(!s.args.fullMatch)return this.func("REGEXP_MATCHES",[t,e,r]);let i=this.validateRegexpFlags(r,"cims"),E=new Lt({expressions:[a.string("^("),new w({this:e}),a.string(")$")]});return i&&(r=a.string(i)),this.func("REGEXP_MATCHES",[t,E,r])}arrayoverlapsSql(s){if(!s.args.nullsafe)return this.binary(s,"&&");let t=s.args.this,e=s.args.expression,r=this.sql(Yt([new Gt({this:new Ut({this:t.copy()}),expression:N("LIST_COUNT",t.copy())}),new Gt({this:new Ut({this:e.copy()}),expression:N("LIST_COUNT",e.copy())})]));return`(${this.binary(s,"&&")}) OR (${r})`}arraycontainsSql(s){let t=s.args.this,e=s.args.expression,r=this.func("ARRAY_CONTAINS",[t,e]);if(s.args.checkNull){let i=new ce({this:new Gt({this:new Ut({this:t}),expression:new m({this:"LIST_COUNT",expressions:[t]})}),expression:new Z({this:!1})});return this.sql(new et({this:new ht({this:e,expression:new ut({})}),true:i,false:y(r)}))}return r}arraydistinctSql(s){let t=s.args.this,e=this.func("LIST_DISTINCT",[t]);if(s.args.checkNull){let r=new m({this:"LIST_APPEND",expressions:[new m({this:"LIST_DISTINCT",expressions:[new Qt({this:t})]}),new ut({})]});return this.sql(new et({this:new Gt({this:new Ut({this:t}),expression:new m({this:"LIST_COUNT",expressions:[t]})}),true:r,false:y(e)}))}return e}regexpinstrSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.occurrence,E=i??a.number(1),c=s.args.option,h=s.args.parameters,A=this.validateRegexpFlags(h?.[0],"ims");A&&(e=new Lt({expressions:[a.string(`(?${A})`),e]}));let O=a.number(0);r&&(!r.isNumber||1<Number(r.toValue()))&&(t=new Pt({this:t,start:r}),O=new G({this:r,expression:a.number(1)}));let M=p((nt,Xt)=>{let Qo=new q({this:new m({this:nt,expressions:[t,e]}),expressions:[new H({this:a.number(1),expression:Xt})],offset:1}),zo=new m({this:"LIST_TRANSFORM",expressions:[Qo,new Nt({this:new j({this:X("x")}),expressions:[X("x")]})]});return new js({this:new m({this:"LIST_SUM",expressions:[zo]}),expressions:[a.number(0)]})},"sumLengths"),U=new I({this:new I({this:new I({this:a.number(1),expression:M("STRING_SPLIT_REGEX",E)}),expression:M("REGEXP_EXTRACT_ALL",new G({this:E,expression:a.number(1)}))}),expression:O});if(c&&c.isNumber&&Number(c.toValue())===1){let nt=new q({this:new m({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),expressions:[E],offset:1});U=new I({this:U,expression:new js({this:new j({this:nt}),expressions:[a.number(0)]})})}let ws=[s.args.this,s.args.expression,r,i,c,h].filter(Boolean).map(nt=>new ht({this:nt.copy(),expression:new ut({})})),lt=new m({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),jo=ot().when(ws.reduce((nt,Xt)=>nt?new Bt({this:nt,expression:Xt}):Xt),new ut({})).when(new Y({this:e.copy(),expression:a.string("")}),a.number(0)).when(new Hs({this:new j({this:lt}),expression:E}),a.number(0)).else(U);return this.sql(jo)}regexpreplaceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.replacement??a.string(""),i=s.args.position,E=s.args.occurrence,c=s.args.modifiers,h=c,A="";if(c&&c.isString&&(A=this.validateRegexpFlags(c,"cimsg")??"",h=void 0),E&&!E.isNumber)this.unsupported("REGEXP_REPLACE with non-literal occurrence");else{let k=E&&E.isNumber?Number(E.toValue()):0;1<k?this.unsupported(`REGEXP_REPLACE occurrence=${k} not supported`):k===0&&!A.includes("g")&&!s.args.singleReplace&&(A+="g")}let O;if(i&&!i.isNumber)this.unsupported("REGEXP_REPLACE with non-literal position");else if(i&&i.isNumber&&1<Number(i.toValue())){let k=Number(i.toValue());O=new Pt({this:t,start:a.number(1),length:a.number(k-1)}),t=new Pt({this:t,start:a.number(k)})}let M=A?a.string(A):h,U=new m({this:"REGEXP_REPLACE",expressions:[t,e,r,...M?[M]:[]].filter(Boolean)});return O&&(U=new Lt({expressions:[O,U]})),this.sql(U)}regexpcountSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.parameters,E=this.validateRegexpFlags(i?.[0],"ims");r&&(t=new Pt({this:t,start:r})),E&&(e=new Lt({expressions:[a.string(`(?${E})`),e]}));let c=new $({ifs:[new et({this:new Y({this:e,expression:a.string("")}),true:a.number(0)})],default:new j({this:new m({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]})})});return this.sql(c)}arrayBagSql(s,t,e){let r=new w({this:b(s.copy(),[],{arr1:t,arr2:e})});return this.sql(b(this._constructor.ARRAY_BAG_TEMPLATE.copy(),[],{arr1:t,arr2:e,cond:r}))}arrayintersectSql(s){return s.args.isMultiset&&s.args.expressions?.length===2?this.arrayBagSql(this._constructor.ARRAY_INTERSECTION_CONDITION,s.args.expressions[0],s.args.expressions[1]):this.functionFallbackSql(s)}arrayexceptSql(s){let t=s.args.this,e=s.args.expression;return s.args.isMultiset?this.arrayBagSql(this._constructor.ARRAY_EXCEPT_CONDITION,t,e):this.sql(b(this._constructor.ARRAY_EXCEPT_SET_TEMPLATE.copy(),[],{arr1:t,arr2:e}))}currentDateSql(s){if(!s.args.this)return"CURRENT_DATE";let t=new T({this:new it({this:new te({}),zone:s.args.this}),to:new l({this:"date"})});return this.sql(t)}parseJsonSql(s){let t=s.args.this;return s.args.safe?this.sql(new $({}).when(this.func("json_valid",[t??g()]),t instanceof d||typeof t=="string"?t:"").else(g())):this.func("JSON",[t])}truncSql(s){return xs.call(this,s,"decimals"),this.func("TRUNC",[s.args.this])}normalSql(s){let t=s.args.this,e=s.args.stddev,r=s.args.gen,i,E;if(r instanceof Q&&!r.args.this)i=new Q({}),E=new Q({});else{let c=(r instanceof Q?r.args.this:r)??g();i=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:c}),E=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:new I({this:c.copy(),expression:a.number(1)})})}return this.sql(b(this._constructor.NORMAL_TEMPLATE.copy(),[],{mean:t,stddev:e,u1:i,u2:E}))}uniformSql(s){let t=s.args.this,e=s.args.expression,r=s.args.gen,i=t instanceof a&&t.isInteger&&e instanceof a&&e.isInteger,E;r instanceof Q?E=new Q({}):E=new at({this:new w({this:new Tt({this:new Ft({this:new m({this:"HASH",expressions:[r||""]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")});let c=new G({this:e,expression:t});i&&(c=new I({this:c,expression:a.number(1)}));let h=new I({this:t,expression:new St({this:E,expression:new w({this:c})})});return i&&(h=new T({this:new ae({this:h}),to:new l({this:"bigint"})})),this.sql(h)}timeFromPartsSql(s){let t=s.args.nano;if(s.args.overflow){let r=K(s.args.hour,"string",a),i=K(s.args.min,"string",a),E=K(s.args.sec,"string",a);if(!t&&[r,i,E].every(h=>h instanceof a&&h.isNumber)){let h=parseInt((r instanceof a?r.args.this:r)??"0"),A=parseInt((i instanceof a?i.args.this:i)??"0"),O=parseInt((E instanceof d?E.args.this:E)??"0");if(0<=h&&h<=23&&0<=A&&A<=59&&0<=O&&O<=59)return x("MAKE_TIME").call(this,s)}t&&(E=E.add(t.pop().div(a.number("1000000000.0"))));let c=r.mul(a.number(3600)).add(i.mul(a.number(60))).add(E);return this.sql(new I({this:new T({this:a.string("00:00:00"),to:l.build("TIME")}),expression:new B({this:c,unit:new P({this:"SECOND"})})}))}return t&&s.setArgKey("sec",new I({this:s.args.sec,expression:new at({this:t.pop(),expression:a.number(1e9)})})),x("MAKE_TIME").call(this,s)}extractSql(s){let t=s.args.expression;t?.isType(["timestamptz","timestampltz"])&&this.unsupported("EXTRACT from TIMESTAMPTZ / TIMESTAMPLTZ may produce different results due to timezone handling differences");let e=K(s.args.this,d)?.name.toUpperCase();if(e!==void 0&&e in u.EXTRACT_STRFTIME_MAPPINGS){let[r,i]=u.EXTRACT_STRFTIME_MAPPINGS[e],E=e==="NANOSECOND"&&t?.isType(["time","timetz"]),c=t??g();if(E)return this.unsupported("Parameter NANOSECOND is not supported with TIME type in DuckDB"),this.sql(new T({this:new St({this:new rs({this:new P({this:"MICROSECOND"}),expression:c}),expression:a.number(1e3)}),to:l.build(i,{dialect:"duckdb"})}));let h=c;return e==="NANOSECOND"&&(h=new T({this:c,to:new l({this:"timestampNs"})})),this.sql(new T({this:new m({this:"STRFTIME",expressions:[h,a.string(r)]}),to:l.build(i,{dialect:"duckdb"})}))}if(e!==void 0&&e in u.EXTRACT_EPOCH_MAPPINGS){let r=u.EXTRACT_EPOCH_MAPPINGS[e],i=new m({this:r,expressions:[t??g()]});return e==="EPOCH_SECOND"&&(i=new T({this:i,to:l.build("BIGINT",{dialect:"duckdb"})})),this.sql(i)}return super.extractSql(s)}timestampFromPartsSql(s){let t=s.args.this,e=s.args.expression;if(t&&e)return this.sql(new I({this:t,expression:e}));let r=s.args.sec;if(!r)return x("MAKE_TIMESTAMP").call(this,s);let i=s.args.milli;i&&(r=new I({this:r,expression:new w({this:new at({this:i.pop(),expression:a.number("1000.0")})})}));let E=s.args.nano;return E&&(r=new I({this:r,expression:new w({this:new at({this:E.pop(),expression:a.number("1000000000.0")})})})),(i||E)&&s.setArgKey("sec",r),x("MAKE_TIMESTAMP").call(this,s)}timestampLtzFromPartsSql(s){let t=s.args.nano;return t&&t.pop(),`CAST(${x("MAKE_TIMESTAMP").call(this,s)} AS TIMESTAMPTZ)`}timestampTzFromPartsSql(s){let t=s.args.zone;t&&(t=t.pop());let e=s.args.nano;e&&e.pop();let r=x("MAKE_TIMESTAMP").call(this,s);return t?`${r} AT TIME ZONE ${this.sql(t)}`:r}tableSampleSql(s,t={}){let e=t.tablesampleKeyword;if(s.parent instanceof st||(e="TABLESAMPLE"),s.args.size){let r=s.args.method;r instanceof d&&r.name?.toUpperCase()!=="RESERVOIR"&&(this.unsupported(`Sampling method ${r} is not supported with a discrete sample count, defaulting to reservoir sampling`),s.setArgKey("method",new P({this:"RESERVOIR"})))}return super.tableSampleSql(s,{tablesampleKeyword:e})}columnDefSql(s,t={}){return s.parent instanceof ze?this.sql(s,"this"):super.columnDefSql(s,t)}joinSql(s){let t=["","inner","outer"].includes(s.args.kind??"");if(!s.args.using&&!s.args.on&&!s.args.method&&t){if(s.args.this instanceof is)return super.joinSql(s.on(new Z({this:!0})));s.setArgKey("side",void 0),s.setArgKey("kind",void 0)}return super.joinSql(s)}generateSeriesSql(s){return ca("GENERATE_SERIES",{exclusiveFuncName:"RANGE"}).call(this,s)}countIfSql(s){return 1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor?this.functionFallbackSql(s):Aa.call(this,s)}bracketSql(s){if(1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor)return super.bracketSql(s);let t=s.args.this;t instanceof W&&t.replace(new w({this:t.copy()}));let e=super.bracketSql(s);if(!s.args.returnsListForMaps){let r=K(t,d),i=r?.type?r:r&&dt(r,{dialect:this.dialect});v(i,"map")&&(e=`(${e})[1]`)}return e}withinGroupSql(s){let t=s.args.this;if(t instanceof qi){let i=s.args.expression;if(!(i instanceof wt))return this.sql(t);let E=t.args.this;t.setArgKey("this",new wt({this:K(t.args.this,d)?.copy(),expressions:i.args.expressions}));let c=this.functionFallbackSql(t);return E instanceof d?this.addArrayAggNullFilter(c,t,E):""}let e=this.sql(s,"expression");if(t instanceof Ss||t instanceof fs){let i=s.find(er);i&&(t.setArgKey("expression",t.args.this),t.setArgKey("this",i.args.this))}return`${this.sql(s,"this").replace(/\)$/,"")}${e})`}lengthSql(s){let t=s.args.this;if(!s.args.binary||t instanceof a&&t.isString)return this.func("LENGTH",[t]);if((t?.type?t:t&&dt(t,{dialect:this.dialect}))?.isType(l.TEXT_TYPES))return this.func("LENGTH",[t]);let r=new T({this:t,to:new l({this:"varbinary"})}),i=new T({this:t,to:new l({this:"varchar"})}),E=new $({this:new m({this:"TYPEOF",expressions:t?[t]:[]})}).when(a.string("BLOB"),new jt({this:r})).else(new m({this:"LENGTH",expressions:[i]}));return this.sql(E)}levenshteinSql(s){xs.call(this,s,"insCost","delCost","subCost");let t=s.args.this,e=s.args.expression,r=s.args.maxDist;if(!r)return this.func("LEVENSHTEIN",[t,e]);let i=new Te({this:t,expression:e});return this.sql(new Zn({this:i,expressions:[r],ignoreNulls:!1}))}padSql(s){let t=s.args.this,e=s.args.fillPattern??a.string(" ");if(J(t)||J(e)){let r=s.args.expression,i=s.args.isLeft,E=new jt({this:t}),c=new G({this:r,expression:E}),h=new pe({this:a.number(0),expressions:[c],ignoreNulls:!0}),A=new xe({this:e,times:[h]}),[O,M]=i?[A,t]:[t,A];return this.sql(new Pr({this:O,expression:M}))}return super.padSql(s)}minhashSql(s){let t=s.args.this,e=s.args.expressions??[];if(e.length!==1||e[0]instanceof or)return this.unsupported("MINHASH with multiple expressions or * requires manual restructuring"),this.func("MINHASH",[t,...e]);let r=b(u.MINHASH_TEMPLATE.copy(),[],{expr:e[0],k:t});return`(${this.sql(r)})`}minhashCombineSql(s){let t=b(u.MINHASH_COMBINE_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}approximateSimilaritySql(s){let t=b(u.APPROXIMATE_SIMILARITY_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}arraySliceSql(s){let t=s.args.start,e=s.args.end;return s.args.zeroBased&&(t&&(t=ot().when(new Mr({this:t.copy(),expression:a.number(0)}),new I({this:t.copy(),expression:a.number(1)}),{copy:!1}),t.setArgKey("default",s.args.start)),e&&(e=ot().when(new Hs({this:e.copy(),expression:a.number(0)}),new G({this:e.copy(),expression:a.number(1)}),{copy:!1}),e.setArgKey("default",s.args.end))),this.func("ARRAY_SLICE",[s.args.this,t,e,s.args.step])}arraysZipSql(s){let t=s.args.expressions??[];if(t.length===0)return this.sql(new W({expressions:[new Se({keys:new W,values:new W})]}));let e=t.map(M=>new j({this:M})),r=e.length===1?e[0]:new pe({this:e[0],expressions:e.slice(1),ignoreNulls:!1}),i=new ft({expressions:t.map((M,U)=>new Ot({this:a.string(`$${U+1}`),expression:g()}))}),E=new I({this:new ys({this:new It({this:"__i"})}),expression:a.number(1)}),c=new ft({expressions:t.map((M,U)=>new Ot({this:a.string(`$${U+1}`),expression:new q({this:new m({this:"COALESCE",expressions:[M,new W({})]}),expressions:[E.copy()]})}))}),h=gs(t.map(M=>M.is(g()))),A=Yt(t.map(M=>new Y({this:new j({this:M}),expression:a.number(0)}))),O=b(u.ARRAYS_ZIP_TEMPLATE.copy(),[],{nullCheck:h,allEmptyCheck:A,emptyStruct:i,maxLen:r,transformStruct:c});return this.sql(O)}lowerSql(s){let t=this.func("LOWER",[tt(s.args.this)]);return pt.call(this,s,t)}upperSql(s){let t=this.func("UPPER",[tt(s.args.this)]);return pt.call(this,s,t)}reverseSql(s){let t=this.func("REVERSE",[tt(s.args.this)]);return pt.call(this,s,t)}randSql(s){s.args.this&&this.unsupported("RANDOM with seed is not supported in DuckDB");let e=s.args.lower,r=s.args.upper;if(e&&r){let i=new w({this:new G({this:r,expression:e})}),E=new I({this:e,expression:new St({this:N("random"),expression:i})});return this.sql(Et(E,"bigint"))}return"RANDOM()"}rightSql(s){let t=s.args.this,e=s.args.expression;if(J(t)){let r=new Yn({this:t}),i=new St({this:e,expression:a.number(2)});return`UNHEX(${this.func("RIGHT",[r,i])})`}return this.func("RIGHT",[t,e])}base64EncodeSql(s){let t=s.args.this;t?.isType(l.TEXT_TYPES)&&(t=new m({this:"ENCODE",expressions:[t]})),t=new Fn({this:t});let e=s.args.maxLineLength,r=s.args.alphabet;t=Wo(t,r);let i=e instanceof a&&e.isNumber?parseInt(e.args.this??"0"):0;if(0<i){let E=new Zr({expressions:[a.number(10)]});t=new Ai({this:new Es({this:t,expression:a.string(`(.{${i}})`),replacement:new Lt({expressions:[a.string("\\1"),E.copy()]})}),expression:E,position:"trailing"})}return this.sql(t)}replaceSql(s){let t=this.func("REPLACE",[tt(s.args.this),tt(s.args.expression),tt(s.args.replacement)]);return pt.call(this,s,t)}bitwiseOp(s,t){va(s);let e=this.binary(s,t);return pt.call(this,s,e)}bitwiseXorSql(s){va(s);let t=this.func("XOR",[s.args.this,s.args.expression]);return pt.call(this,s,t)}objectInsertSql(s){let t=s.args.this,e=s.args.key,r=e instanceof d?e.name:"",i=this.sql(s,"value"),E=`${r} := ${i}`;return t instanceof ft&&(!t.args.expressions||t.args.expressions.length===0)?this.func("STRUCT_PACK",[E]):this.func("STRUCT_INSERT",[t,E])}mapCatSql(s){let t=b(u.MAPCAT_TEMPLATE.copy(),[],{map1:s.args.this,map2:s.args.expression});return this.sql(t)}mapDeleteSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Gs({this:X("x"),expression:X("key")}),i=new Jt({this:new Zt({this:r,expressions:e})}),E=new Nt({this:i,expressions:[X("x")]}),c=new ts({this:N("map_entries",t),expression:E}),h=N("map_from_entries",c);return this.sql(h)}mapSizeSql(s){return this.func("CARDINALITY",[s.args.this])}mapPickSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Gs({this:X("x"),expression:X("key")}),i;e.length===1&&e[0].isType?.("array")?i=new Nt({this:N("ARRAY_CONTAINS",e[0],r),expressions:[X("x")]}):i=new Nt({this:new Zt({this:r,expressions:e}),expressions:[X("x")]});let E=N("MAP_FROM_ENTRIES",N("LIST_FILTER",N("MAP_ENTRIES",t),i));return this.sql(E)}mapInsertSql(s){s.args.updateFlag&&this.unsupported("MAP_INSERT update_flag is not supported in DuckDB");let t=s.args.this,e=s.args.key,r=s.args.value;if(r!==void 0&&t){let h=t.type;if(h instanceof l&&h.args.expressions&&1<h.args.expressions.length){let A=h.args.expressions[1];r=Et(r,A)}}let i=new ft({expressions:[new Ot({this:e,expression:r})]}),E=new fe({this:i}),c=N("MAP_CONCAT",t,E);return this.sql(c)}startsWithSql(s){return this.func("STARTS_WITH",[tt(s.args.this),tt(s.args.expression)])}spaceSql(s){return this.sql(new xe({this:a.string(" "),times:[new T({this:s.args.this,to:new l({this:"bigint"})})]}))}tableFromRowsSql(s){if(s.args.this instanceof ks){let t=new Ps({this:s.args.this,alias:s.args.alias,joins:s.args.joins});return this.sql(t)}return super.tableFromRowsSql(s)}unnestSql(s){if(s.args.explodeArray){s.args.expressions||s.setArgKey("expressions",[]),s.args.expressions?.push(new Us({this:new P({this:"max_depth"}),expression:a.number(2)}));let e=s.args.alias;e instanceof Dt&&(s.setArgKey("alias",void 0),e.args.columns&&0<e.args.columns.length&&(e=new Dt({this:R(e.args.columns,0)})));let r=super.unnestSql(s),i=e?` AS ${this.sql(e)}`:"";return`(SELECT ${r})${i}`}return super.unnestSql(s)}ignoreNullsSql(s){let t=s.args.this;if(this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(r=>t instanceof r))return super.ignoreNullsSql(s);let e=t;return e instanceof Fi&&(e=new Ht({this:e.args.this})),e instanceof Ht||e instanceof Mi||this.unsupported("IGNORE NULLS is not supported for non-window functions."),this.sql(e)}splitSql(s){let t=N("STR_SPLIT",s.args.this,s.args.expression),e=ot();e.setArgKey("default",t);let r=!1;return s.args.nullReturnsNull&&(e=e.when(new ht({this:s.args.expression,expression:new ut({})}),new ut({}),{copy:!1}),r=!0),s.args.emptyDelimiterReturnsWhole&&(e=e.when(new Y({this:s.args.expression.copy(),expression:a.string("")}),sa([s.args.this]),{copy:!1}),r=!0),this.sql(r?e:t)}splitPartSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){s.args.partIndexZeroAsOne&&(r=new w({this:ot().when(new Y({this:r.copy(),expression:a.number(0)}),a.number(1),{copy:!1})}),r.args.this.setArgKey("default",s.args.partIndex));let i=new m({this:"SPLIT_PART",expressions:[t,e,r].filter(Boolean)}),E=!1,c=ot();if(c.setArgKey("default",i),s.args.emptyDelimiterReturnsWhole){let h=new w({this:ot().when(new Bt({this:new Y({this:r.copy(),expression:a.number(1)}),expression:new Y({this:r.copy(),expression:a.number(-1)})}),t,{copy:!1})});h.args.this.setArgKey("default",a.string("")),c=c.when(new Y({this:e.copy(),expression:a.string("")}),h,{copy:!1}),E=!0}return this.sql(E?c:i)}return this.functionFallbackSql(s)}respectNullsSql(s){return this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(t=>s.args.this instanceof t)?super.respectNullsSql(s):(this.unsupported("RESPECT NULLS is not supported for non-window functions."),this.sql(s,"this"))}arrayToStringSql(s){let t=this.sql(s,"this"),e=this.sql(s,"null");return e&&(t=`LIST_TRANSFORM(${t}, x -> COALESCE(x, ${e}))`),this.func("ARRAY_TO_STRING",[t,s.args.expression])}regexpExtractCommon(s){let t=s.args.this,e=s.args.group,r=s.args.parameters,i=s.args.position,E=s.args.occurrence,c="nullIfPosOverflow"in s.args?s.args.nullIfPosOverflow:void 0;r&&r.isString&&(r.name??"").includes("e")&&(r=a.string((r.name??"").replace(/e/g,"")));let h=this.validateRegexpFlags(r,"cims"),A=e,O=String(this.dialect._constructor.REGEXP_EXTRACT_DEFAULT_GROUP);!h&&e&&(e instanceof It&&e.name===O||e instanceof a&&String(e.args.this)===O)&&(A=void 0);let M=h?a.string(h):void 0;i&&(!(i instanceof a&&i.isInteger)||1<parseInt(i.args.this??"0"))&&(t=new Pt({this:t,start:i}),c&&(t=new ce({this:t,expression:a.string("")})));let U=s instanceof ge,k=E&&(!(E instanceof a&&E.isInteger)||1<parseInt(E.args.this??"0")),ws=U||k?"REGEXP_EXTRACT_ALL":"REGEXP_EXTRACT",lt=new m({this:ws,expressions:[t,s.args.expression,A,M].filter(Boolean)});return U&&k?lt=new q({this:lt,expressions:[new H({this:E})]}):k&&(lt=new m({this:"ARRAY_EXTRACT",expressions:[lt,E]})),this.sql(lt)}regexpExtractSql(s){return this.regexpExtractCommon(s)}regexpExtractAllSql(s){return this.regexpExtractCommon(s)}numberToStrSql(s){if(s.args.culture)return this.unsupported("DuckDB does not support the culture argument in NumberToStr"),this.functionFallbackSql(s);let t=s.args.format?.name;return t&&/^\d+$/.test(t)?this.func("FORMAT",[a.string(`{:,.${t}f}`),s.args.this]):(this.unsupported("Only integer formats are supported by NumberToStr"),this.functionFallbackSql(s))}autoIncrementColumnConstraintSql(s){return this.unsupported("The AUTOINCREMENT column constraint is not supported by DuckDB"),""}aliasesSql(s){let t=s.args.this;return t instanceof Vi?this.posexplodeSql(t):super.aliasesSql(s)}posexplodeSql(s){let t=s.args.this,e=s.parent,r=new It({this:"pos",quoted:!1}),i=new It({this:"col",quoted:!1});if(e instanceof pr){let A=e.args.expressions;r=A?.[0],i=A?.[1]}else if(e instanceof Ps){let A=e.args.alias;if(A instanceof Dt){let O=A.args.columns;O&&0<O.length&&(r=O[0],i=O[1]??i),A.pop()}}let E=this.sql(new is({expressions:[t],alias:i})),c=this.sql(new Cs({this:new G({this:new m({this:"GENERATE_SUBSCRIPTS",expressions:[t,a.number(1)]}),expression:a.number(1)}),alias:r})),h=this.formatArgs([c,E]);return e instanceof Ls||e&&e.parent instanceof Ls?`(SELECT ${h})`:h}addMonthsSql(s){let t=s.args.this;t?.type||(t=t&&dt(t,{dialect:this.dialect})),t?.isType(l.TEXT_TYPES)&&(t=new T({this:t,to:new l({this:"timestamp"})}));let e=s.args.expression,r=e?.type?e:e&&dt(e,{dialect:this.dialect}),i;r?.isType(["float","double","decimal"])?i=new m({this:"TO_MONTHS",expressions:[new T({this:new m({this:"ROUND",expressions:e&&[e]}),to:new l({this:"int"})})]}):i=new B({this:e,unit:new P({this:"MONTH"})});let E=new I({this:t,expression:i}),c=s.args.preserveEndOfMonth,h=E;return c&&(h=new $({}).when(new Y({this:N("LAST_DAY",t),expression:t}),N("LAST_DAY",E)).else(E)),t?.isType(["date","timestamptz"])?this.sql(new T({this:h,to:t.type})):this.sql(h)}formatSql(s){return s.name.toLowerCase()==="%s"&&s.args.expressions?.length===1?this.func("FORMAT",[a.string("{}"),s.args.expressions[0]]):this.functionFallbackSql(s)}dateTruncSql(s){let t=s.args.unit,e=s.args.this,r=Zo(t),i=Mt(s),E;return r?E=this.sql(Be(e,r,{preserveStartDay:!0})):E=this.func("DATE_TRUNC",[i,e]),s.args.inputTypePreserved&&e?.isType(l.TEMPORAL_TYPES)&&!(_s(i)&&e.isType("date"))?this.sql(new T({this:E,to:e.type})):E}timestampTruncSql(s){let t=Mt(s),e=s.args.zone,r=s.args.this,i=_s(t);if(i&&e){r=new it({this:r,zone:e});let c=this.func("DATE_TRUNC",[t,r]);return this.sql(new it({this:c,zone:e}))}let E=this.func("DATE_TRUNC",[t,r]);if(s.args.inputTypePreserved){if(r?.isType(["time","timetz"])){let c=new T({this:a.string("1970-01-01"),to:new l({this:"date"})}),h=new I({this:c,expression:r});return E=this.func("DATE_TRUNC",[t,h]),this.sql(new T({this:E,to:r.type}))}if(r?.isType(l.TEMPORAL_TYPES)&&!(i&&r.isType("date")))return this.sql(new T({this:E,to:r.type}))}return E}trimSql(s){let t=tt(s.args.this);if(t&&s.setArgKey("this",t),s.args.expression instanceof d){let r=tt(s.args.expression);r&&s.setArgKey("expression",r)}let e=super.trimSql(s);return pt.call(this,s,e)}hexStringSql(s){return super.hexStringSql(s,{binaryFunctionRepr:"UNHEX"})}roundSql(s){let t=s.args.this,e=s.args.decimals,r=s.args.truncate;e&&s.args.castsNonIntegerDecimals&&(e.isInteger||e.isType([...l.INTEGER_TYPES])||(e=new T({this:e,to:new l({this:"int"})})));let i="ROUND";if(r instanceof a){let E=r.args.this?.toUpperCase();E!==void 0&&["ROUND_HALF_EVEN","HALF_TO_EVEN"].includes(E)?(i="ROUND_EVEN",r=void 0):E!==void 0&&["ROUND_HALF_AWAY_FROM_ZERO","HALF_AWAY_FROM_ZERO"].includes(E)&&(r=void 0)}return this.func(i,[t,e,r])}approxQuantileSql(s){let t=this.func("APPROX_QUANTILE",[s.args.this,s.args.quantile]);return s.isType(l.REAL_TYPES)&&(t=`CAST(${t} AS DOUBLE)`),t}approxQuantilesSql(s){let t=s.args.this,e;if(t instanceof Ms){if(!t.args.expressions||t.args.expressions.length<2)return this.unsupported("APPROX_QUANTILES requires a bucket count argument"),this.functionFallbackSql(s);e=t.args.expressions[1].pop()}else e=s.args.expression;if(!(e instanceof a&&e.isInteger))return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let r=parseInt(e.args.this??"0");if(r<=0)return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let i=Array.from({length:r+1},(E,c)=>a.number(c/r));return this.sql(new Me({this:t,quantile:new W({expressions:i})}))}jsonExtractScalarSql(s){return s.args.scalarOnly&&(s=new he({this:new m({this:"JSON_VALUE",expressions:[s.args.this,s.args.expression].filter(t=>t instanceof d)}),expression:a.string("$")})),Ua.call(this,s)}bitwiseNotSql(s){let t=s.args.this;J(t)&&(s.type=new l({this:"binary"}));let e=ve(t);t instanceof yr&&(e=new w({this:e})),s.setArgKey("this",e);let r=`~${this.sql(s,"this")}`;return pt.call(this,s,r)}windowSql(s){let t=s.args.this;return t instanceof gt||t instanceof Kt&&t.args.this instanceof gt?this.corrSql(s):super.windowSql(s)}filterSql(s){return s.args.this instanceof gt?this.corrSql(s):super.filterSql(s)}corrSql(s){if(s instanceof gt&&!s.args.nullOnZeroVariance)return this.func("CORR",[s.args.this,s.args.expression]);let t=LE(s);return t?this.sql(new $({}).when(new le({this:t}),g()).else(t)):s instanceof Wt?super.windowSql(s):s instanceof Kt?super.filterSql(s):this.sql(s)}};_=yt(Bo),S(_,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",Ho,u),S(_,10,"STRUCT_DELIMITER",Uo,u),S(_,10,"ORIGINAL_TRANSFORMS",Fo,u),S(_,10,"SUPPORTED_JSON_PATH_PARTS",Go,u),S(_,10,"TYPE_MAPPING",Do,u),S(_,10,"RESERVED_KEYWORDS",bo,u),S(_,10,"UNWRAPPED_INTERVAL_VALUES",qo,u),S(_,10,"PROPERTIES_LOCATION",yo,u),S(_,10,"IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS",Mo,u),S(_,10,"ZIPF_TEMPLATE",Co,u),S(_,10,"NORMAL_TEMPLATE",Po,u),S(_,10,"SEEDED_RANDOM_TEMPLATE",Lo,u),S(_,10,"SEQ_UNSIGNED",Oo,u),S(_,10,"SEQ_SIGNED",_o,u),S(_,10,"MAPCAT_TEMPLATE",wo,u),S(_,10,"EXTRACT_STRFTIME_MAPPINGS",No,u),S(_,10,"EXTRACT_EPOCH_MAPPINGS",Io,u),S(_,10,"BITMAP_CONSTRUCT_AGG_TEMPLATE",mo,u),S(_,10,"RANDSTR_TEMPLATE",Ro,u),S(_,10,"MINHASH_TEMPLATE",xo,u),S(_,10,"MINHASH_COMBINE_TEMPLATE",Ao,u),S(_,10,"APPROXIMATE_SIMILARITY_TEMPLATE",go,u),S(_,10,"ARRAYS_ZIP_TEMPLATE",fo,u),qt(_,u),bt(_,3,u),p(u,"DuckDBGenerator"),u.SUPPORTS_DECODE_CASE=!1,u.SELECT_KINDS=[],u.PARAMETER_TOKEN="$",u.NAMED_PLACEHOLDER_TOKEN="$",u.JOIN_HINTS=!1,u.TABLE_HINTS=!1,u.QUERY_HINTS=!1,u.LIMIT_FETCH="LIMIT",u.RENAME_TABLE_WITH_DB=!1,u.NVL2_SUPPORTED=!1,u.SEMI_ANTI_JOIN_WITH_SIDE=!1,u.TABLESAMPLE_KEYWORDS="USING SAMPLE",u.TABLESAMPLE_SEED_KEYWORD="REPEATABLE",u.LAST_DAY_SUPPORTS_DATE_PART=!1,u.JSON_KEY_VALUE_PAIR_SEP=",",u.IGNORE_NULLS_IN_FUNC=!0,u.IGNORE_NULLS_BEFORE_ORDER=!1,u.JSON_PATH_BRACKETED_KEY_SUPPORTED=!1,u.SUPPORTS_CREATE_TABLE_LIKE=!1,u.MULTI_ARG_DISTINCT=!1,u.CAN_IMPLEMENT_ARRAY_ANY=!0,u.SUPPORTS_TO_NUMBER=!1,u.SUPPORTS_WINDOW_EXCLUDE=!0,u.COPY_HAS_INTO_KEYWORD=!1,u.STAR_EXCEPT="EXCLUDE",u.PAD_FILL_PATTERN_IS_REQUIRED=!0,u.ARRAY_SIZE_DIM_REQUIRED=!1,u.NORMALIZE_EXTRACT_DATE_PARTS=!0,u.SUPPORTS_LIKE_QUANTIFIERS=!1,u.SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD=!0,u.ARRAY_BAG_TEMPLATE=y(`CASE
|
|
94
|
+
`)}timeSliceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.unit,i=s.text("kind").toUpperCase(),E=new Y({this:e,unit:r}),c=this.func("time_bucket",[E,t]);if(i!=="END")return this.sql(c);let u=new I({this:c,expression:E.copy()});return t?.isType("date")?this.sql(new T({this:u,to:new l({this:"date"})})):this.sql(u)}bitmapBucketNumberSql(s){let t=s.args.this,e=new I({this:new L({this:new Qt({this:new L({this:new F({this:t,expression:a.number(1)})}),expression:a.number(32768)})}),expression:a.number(1)}),r=new Qt({this:t,expression:a.number(32768)});return this.sql(new $({}).when(new Ys({this:t,expression:a.number(0)}),e).else(r))}bitmapBitPositionSql(s){let t=s.args.this;return this.sql(new St({this:new L({this:new Q({this:new Ys({this:t,expression:a.number(0)}),true:new F({this:t,expression:a.number(1)}),false:new Ut({this:t})})}),expression:iE}))}bitmapConstructAggSql(s){let t=s.args.this;return`(${this.sql(b(this._constructor.BITMAP_CONSTRUCT_AGG_TEMPLATE.copy(),[],{arg:t}))})`}nthValueSql(s){return(s.args.fromFirst??!0)||this.unsupported("DuckDB's NTH_VALUE doesn't support starting from the end"),this.functionFallbackSql(s)}randstrSql(s){let t=s.args.this,e=s.args.generator,r;return e?e instanceof tt?r=e.args.this??e:r=e:r=a.number(nE),`(${this.sql(b(this._constructor.RANDSTR_TEMPLATE.copy(),[],{seed:r,length:t}))})`}zipfSql(s){let t=s.args.this,e=s.args.elementcount,r=s.args.gen,i;return r instanceof tt?i=new tt({}):i=new lt({this:new L({this:new St({this:new Ut({this:new d({this:"HASH",expressions:[(r??f()).copy()]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")}),`(${this.sql(b(this._constructor.ZIPF_TEMPLATE.copy(),[],{s:t,n:e,randomExpr:i}))})`}toBinarySql(s){let t=s.args.this,e=K(s.args.format,N),r=s.args.safe,i=Z(s);if(!e&&!i){let u=r?"TRY_TO_BINARY":"TO_BINARY";return this.func(u,[t])}let E=e?.name?.toUpperCase()??"HEX",c;if(E==="UTF-8"||E==="UTF8")c=this.func("ENCODE",[t]);else if(E==="BASE64")c=this.func("FROM_BASE64",[t]);else if(E==="HEX")c=this.func("UNHEX",[t]);else{if(r)return this.sql(f());this.unsupported(`format ${E} is not supported`),c=this.func("TO_BINARY",[t])}return r?`TRY(${c})`:c}greatestLeastSql(s){let t=[s.args.this,...s.args.expressions??[]],e=this.functionFallbackSql(s);if(s.args.ignoreNulls)return this.sql(e);let r=new $({}).when(Kt(t.map(i=>(i??f()).is(f())),{copy:!1}),f());return r.setArgKey("default",e),this.sql(r)}generatorSql(s){let t=s.args.rowcount;return s.args.timelimit&&this.unsupported("GENERATOR TIMELIMIT parameter is not supported in DuckDB"),t?this.func("range",[t]):(this.unsupported("GENERATOR without ROWCOUNT is not supported in DuckDB"),this.func("range",[a.number(0)]))}greatestSql(s){return this.greatestLeastSql(s)}leastSql(s){return this.greatestLeastSql(s)}lambdaSql(s,t={}){let e=t.arrowSep??"->",r=t.wrap??!0,i="";s.args.colon&&(i="LAMBDA ",e=":",r=!1);let E=super.lambdaSql(s,{arrowSep:e,wrap:r});return`${i}${E}`}sortArraySql(s){let t=s.args.this,e=s.args.asc,r=s.args.nullsFirst;if(!(e instanceof j)&&!(r instanceof j))return this.func("LIST_SORT",[t,e,r]);let i=r instanceof j&&r.args.this===!0,E=i?a.string("NULLS FIRST"):void 0;if(!(e instanceof j))return this.func("LIST_SORT",[t,e,E]);let c=e.args.this===!1;return!c&&!i?this.func("LIST_SORT",[t]):i?this.func("LIST_SORT",[t,a.string(c?"DESC":"ASC"),a.string("NULLS FIRST")]):this.func("ARRAY_REVERSE_SORT",[t])}showSql(s){let t=this.sql(s,"from"),e=t?` FROM ${t}`:"";return`SHOW ${s.name}${e}`}installSql(s){let t=s.args.force?"FORCE ":"",e=this.sql(s,"this"),r=s.args.from?` FROM ${s.args.from}`:"";return`${t}INSTALL ${e}${r}`}approxTopKSql(s){return this.unsupported("APPROX_TOP_K cannot be transpiled to DuckDB due to incompatible return types. "),this.functionFallbackSql(s)}fromIso8601TimestampSql(s){return this.sql(new T({this:s.args.this,to:new l({this:"timestamptz"})}))}strToTimeSql(s){let t=s.args.targetType,e=t&&["timestampltz","timestamptz"].includes(t.args.this);if(s.args.safe){let i=this.formatTime(s),E=e?"timestamptz":"timestamp";return this.sql(new T({this:this.func("TRY_STRPTIME",[s.args.this,i]),to:new l({this:E})}))}let r=Ra.call(this,s);return e?this.sql(new T({this:r,to:new l({this:"timestamptz"})})):r}strToDateSql(s){let t=this.formatTime(s),e=s.args.safe?"TRY_STRPTIME":"STRPTIME";return this.sql(new T({this:this.func(e,[s.args.this,t]),to:new l({this:"date"})}))}tsOrDsToTimeSql(s){let t=s.args.this,e=this.formatTime(s),r=s.args.safe,i=l.build("time",{dialect:"duckdb"}),E=r?Yi:T;if(e){let c=r?"TRY_STRPTIME":"STRPTIME",u=new d({this:c,expressions:[t??f(),e]});return this.sql(new E({this:u,to:i}))}return t instanceof mi||t?.isType("time")?this.sql(t??f()):this.sql(new E({this:t,to:i}))}validateRegexpFlags(s,t){if(!(s instanceof N))return;if(!s.isString){this.unsupported("Non-literal regexp flags are not fully supported in DuckDB");return}let e=s.name??"",r=new Set(t),i=[...new Set(e)].filter(c=>!r.has(c));return 0<i.length&&this.unsupported(`Regexp flags ${JSON.stringify(i.sort())} are not supported in this context`),[...e].filter(c=>r.has(c)).join("")||void 0}regexplikeSql(s){let t=s.args.this,e=s.args.expression,r=s.args.flag;if(s.args.fullMatch){let i=this.validateRegexpFlags(r,"cims");return r=i?a.string(i):void 0,this.func("REGEXP_FULL_MATCH",[t,e,r])}return this.func("REGEXP_MATCHES",[t,e,r])}arrayoverlapsSql(s){if(!s.args.nullsafe)return this.binary(s,"&&");let t=s.args.this,e=s.args.expression,r=this.sql(Vt([new Ft({this:new Bt({this:t.copy()}),expression:x("LIST_COUNT",t.copy())}),new Ft({this:new Bt({this:e.copy()}),expression:x("LIST_COUNT",e.copy())})]));return`(${this.binary(s,"&&")}) OR (${r})`}arraycontainsSql(s){let t=s.args.this,e=s.args.expression,r=this.func("ARRAY_CONTAINS",[t,e]);if(s.args.checkNull){let i=new he({this:new Ft({this:new Bt({this:t}),expression:new d({this:"LIST_COUNT",expressions:[t]})}),expression:new j({this:!1})});return this.sql(new Q({this:new at({this:e,expression:new it({})}),true:i,false:y(r)}))}return r}arrayUniqueAggSql(s){let t=s.args.this;return this.sql(new Gt({this:x("LIST",new bs({expressions:[t]})),expression:new Ms({this:new Ot({this:new at({this:t.copy(),expression:new it})})})}))}arraydistinctSql(s){let t=s.args.this,e=this.func("LIST_DISTINCT",[t]);if(s.args.checkNull){let r=new d({this:"LIST_APPEND",expressions:[new d({this:"LIST_DISTINCT",expressions:[new ss({this:t})]}),new it({})]});return this.sql(new Q({this:new Ft({this:new Bt({this:t}),expression:new d({this:"LIST_COUNT",expressions:[t]})}),true:r,false:y(e)}))}return e}regexpinstrSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.occurrence,E=i??a.number(1),c=s.args.option,u=s.args.parameters,A=this.validateRegexpFlags(u?.[0],"ims");A&&(e=new vt({expressions:[a.string(`(?${A})`),e]}));let _=a.number(0);r&&(!r.isNumber||1<Number(r.toValue()))&&(t=new Pt({this:t,start:r}),_=new F({this:r,expression:a.number(1)}));let O=p((pt,Jt)=>{let tE=new q({this:new d({this:pt,expressions:[t,e]}),expressions:[new B({this:a.number(1),expression:Jt})],offset:1}),sE=new d({this:"LIST_TRANSFORM",expressions:[tE,new rt({this:new z({this:H("x")}),expressions:[H("x")]})]});return new Yt({this:new d({this:"LIST_SUM",expressions:[sE]}),expressions:[a.number(0)]})},"sumLengths"),G=new I({this:new I({this:new I({this:a.number(1),expression:O("STRING_SPLIT_REGEX",E)}),expression:O("REGEXP_EXTRACT_ALL",new F({this:E,expression:a.number(1)}))}),expression:_});if(c&&c.isNumber&&Number(c.toValue())===1){let pt=new q({this:new d({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),expressions:[E],offset:1});G=new I({this:G,expression:new Yt({this:new z({this:pt}),expressions:[a.number(0)]})})}let Ls=[s.args.this,s.args.expression,r,i,c,u].filter(Boolean).map(pt=>new at({this:pt.copy(),expression:new it({})})),Tt=new d({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]}),zo=J().when(Ls.reduce((pt,Jt)=>pt?new Xt({this:pt,expression:Jt}):Jt),new it({})).when(new v({this:e.copy(),expression:a.string("")}),a.number(0)).when(new ks({this:new z({this:Tt}),expression:E}),a.number(0)).else(G);return this.sql(zo)}regexpreplaceSql(s){let t=s.args.this,e=s.args.expression,r=s.args.replacement??a.string(""),i=s.args.position,E=s.args.occurrence,c=s.args.modifiers,u=c,A="";if(c&&c.isString&&(A=this.validateRegexpFlags(c,"cimsg")??"",u=void 0),E&&!E.isNumber)this.unsupported("REGEXP_REPLACE with non-literal occurrence");else{let V=E&&E.isNumber?Number(E.toValue()):0;1<V?this.unsupported(`REGEXP_REPLACE occurrence=${V} not supported`):V===0&&!A.includes("g")&&!s.args.singleReplace&&(A+="g")}let _;if(i&&!i.isNumber)this.unsupported("REGEXP_REPLACE with non-literal position");else if(i&&i.isNumber&&1<Number(i.toValue())){let V=Number(i.toValue());_=new Pt({this:t,start:a.number(1),length:a.number(V-1)}),t=new Pt({this:t,start:a.number(V)})}let O=A?a.string(A):u,G=new d({this:"REGEXP_REPLACE",expressions:[t,e,r,...O?[O]:[]].filter(Boolean)});return _&&(G=new vt({expressions:[_,G]})),this.sql(G)}regexpcountSql(s){let t=s.args.this,e=s.args.expression,r=s.args.position,i=s.args.parameters,E=this.validateRegexpFlags(i?.[0],"ims");r&&(t=new Pt({this:t,start:r})),E&&(e=new vt({expressions:[a.string(`(?${E})`),e]}));let c=new $({ifs:[new Q({this:new v({this:e,expression:a.string("")}),true:a.number(0)})],default:new z({this:new d({this:"REGEXP_EXTRACT_ALL",expressions:[t,e]})})});return this.sql(c)}arrayBagSql(s,t,e){let r=new L({this:b(s.copy(),[],{arr1:t,arr2:e})});return this.sql(b(this._constructor.ARRAY_BAG_TEMPLATE.copy(),[],{arr1:t,arr2:e,cond:r}))}arrayintersectSql(s){return s.args.isMultiset&&s.args.expressions?.length===2?this.arrayBagSql(this._constructor.ARRAY_INTERSECTION_CONDITION,s.args.expressions[0],s.args.expressions[1]):this.functionFallbackSql(s)}arrayexceptSql(s){let t=s.args.this,e=s.args.expression;return s.args.isMultiset?this.arrayBagSql(this._constructor.ARRAY_EXCEPT_CONDITION,t,e):this.sql(b(this._constructor.ARRAY_EXCEPT_SET_TEMPLATE.copy(),[],{arr1:t,arr2:e}))}currentDateSql(s){if(!s.args.this)return"CURRENT_DATE";let t=new T({this:new ct({this:new re({}),zone:s.args.this}),to:new l({this:"date"})});return this.sql(t)}checkJsonSql(s){let t=s.args.this;return this.sql(J().when(Kt([new at({this:t,expression:new it}),t.eq(a.string("")),x("json_valid",t)]),f()).else(a.string("Invalid JSON")))}parseJsonSql(s){let t=s.args.this;return s.args.safe?this.sql(new $({}).when(this.func("json_valid",[t??f()]),t instanceof N||typeof t=="string"?t:"").else(f())):this.func("JSON",[t])}truncSql(s){return ds.call(this,s,"decimals"),this.func("TRUNC",[s.args.this])}normalSql(s){let t=s.args.this,e=s.args.stddev,r=s.args.gen,i,E;if(r instanceof tt&&!r.args.this)i=new tt({}),E=new tt({});else{let c=(r instanceof tt?r.args.this:r)??f();i=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:c}),E=b(this._constructor.SEEDED_RANDOM_TEMPLATE.copy(),[],{seed:new I({this:c.copy(),expression:a.number(1)})})}return this.sql(b(this._constructor.NORMAL_TEMPLATE.copy(),[],{mean:t,stddev:e,u1:i,u2:E}))}uniformSql(s){let t=s.args.this,e=s.args.expression,r=s.args.gen,i=t instanceof a&&t.isInteger&&e instanceof a&&e.isInteger,E;r instanceof tt?E=new tt({}):E=new lt({this:new L({this:new St({this:new Ut({this:new d({this:"HASH",expressions:[r||""]})}),expression:a.number(1e6)})}),expression:a.number("1000000.0")});let c=new F({this:e,expression:t});i&&(c=new I({this:c,expression:a.number(1)}));let u=new I({this:t,expression:new gt({this:E,expression:new L({this:c})})});return i&&(u=new T({this:new pe({this:u}),to:new l({this:"bigint"})})),this.sql(u)}timeFromPartsSql(s){let t=s.args.nano;if(s.args.overflow){let r=K(s.args.hour,"string",a),i=K(s.args.min,"string",a),E=K(s.args.sec,"string",a);if(!t&&[r,i,E].every(u=>u instanceof a&&u.isNumber)){let u=parseInt((r instanceof a?r.args.this:r)??"0"),A=parseInt((i instanceof a?i.args.this:i)??"0"),_=parseInt((E instanceof N?E.args.this:E)??"0");if(0<=u&&u<=23&&0<=A&&A<=59&&0<=_&&_<=59)return R("MAKE_TIME").call(this,s)}t&&(E=E.add(t.pop().div(a.number("1000000000.0"))));let c=r.mul(a.number(3600)).add(i.mul(a.number(60))).add(E);return this.sql(new I({this:new T({this:a.string("00:00:00"),to:l.build("time")}),expression:new Y({this:c,unit:new C({this:"SECOND"})})}))}return t&&s.setArgKey("sec",new I({this:s.args.sec,expression:new lt({this:t.pop(),expression:a.number(1e9)})})),R("MAKE_TIME").call(this,s)}extractSql(s){let t=s.args.expression;t?.isType(["timestamptz","timestampltz"])&&this.unsupported("EXTRACT from TIMESTAMPTZ / TIMESTAMPLTZ may produce different results due to timezone handling differences");let e=K(s.args.this,N)?.name.toUpperCase();if(e!==void 0&&e in h.EXTRACT_STRFTIME_MAPPINGS){let[r,i]=h.EXTRACT_STRFTIME_MAPPINGS[e],E=e==="NANOSECOND"&&t?.isType(["time","timetz"]),c=t??f();if(E)return this.unsupported("Parameter NANOSECOND is not supported with TIME type in DuckDB"),this.sql(new T({this:new gt({this:new as({this:new C({this:"MICROSECOND"}),expression:c}),expression:a.number(1e3)}),to:l.build(i,{dialect:"duckdb"})}));let u=c;return e==="NANOSECOND"&&(u=new T({this:c,to:new l({this:"timestampNs"})})),this.sql(new T({this:new d({this:"STRFTIME",expressions:[u,a.string(r)]}),to:l.build(i,{dialect:"duckdb"})}))}if(e!==void 0&&e in h.EXTRACT_EPOCH_MAPPINGS){let r=h.EXTRACT_EPOCH_MAPPINGS[e],i=new d({this:r,expressions:[t??f()]});return e==="EPOCH_SECOND"&&(i=new T({this:i,to:l.build("bigint",{dialect:"duckdb"})})),this.sql(i)}return super.extractSql(s)}timestampFromPartsSql(s){let t=s.args.this,e=s.args.expression;if(t&&e)return this.sql(new I({this:t,expression:e}));let r=s.args.sec;if(!r)return R("MAKE_TIMESTAMP").call(this,s);let i=s.args.milli;i&&(r=new I({this:r,expression:new L({this:new lt({this:i.pop(),expression:a.number("1000.0")})})}));let E=s.args.nano;return E&&(r=new I({this:r,expression:new L({this:new lt({this:E.pop(),expression:a.number("1000000000.0")})})})),(i||E)&&s.setArgKey("sec",r),R("MAKE_TIMESTAMP").call(this,s)}timestampLtzFromPartsSql(s){let t=s.args.nano;return t&&t.pop(),`CAST(${R("MAKE_TIMESTAMP").call(this,s)} AS TIMESTAMPTZ)`}timestampTzFromPartsSql(s){let t=s.args.zone;t&&(t=t.pop());let e=s.args.nano;e&&e.pop();let r=R("MAKE_TIMESTAMP").call(this,s);return t?`${r} AT TIME ZONE ${this.sql(t)}`:r}tableSampleSql(s,t={}){let e=t.tablesampleKeyword;if(s.parent instanceof nt||(e="TABLESAMPLE"),s.args.size){let r=s.args.method;r instanceof N&&r.name?.toUpperCase()!=="RESERVOIR"&&(this.unsupported(`Sampling method ${r} is not supported with a discrete sample count, defaulting to reservoir sampling`),s.setArgKey("method",new C({this:"RESERVOIR"})))}return super.tableSampleSql(s,{tablesampleKeyword:e})}columnDefSql(s,t={}){return s.parent instanceof sr?this.sql(s,"this"):super.columnDefSql(s,t)}joinSql(s){let t=["","inner","outer"].includes(s.args.kind??"");if(!s.args.using&&!s.args.on&&!s.args.method&&t){if(s.args.this instanceof Es)return super.joinSql(s.on(new j({this:!0})));s.setArgKey("side",void 0),s.setArgKey("kind",void 0)}return super.joinSql(s)}generateSeriesSql(s){return la("GENERATE_SERIES",{exclusiveFuncName:"RANGE"}).call(this,s)}countIfSql(s){return 1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor?this.functionFallbackSql(s):xa.call(this,s)}bracketSql(s){if(1<this.dialect.version.major||this.dialect.version.major===1&&2<=this.dialect.version.minor)return super.bracketSql(s);let t=s.args.this;t instanceof W&&t.replace(new L({this:t.copy()}));let e=super.bracketSql(s);if(!s.args.returnsListForMaps){let r=K(t,N),i=r?.type?r:r&&Nt(r,{dialect:this.dialect});k(i,"map")&&(e=`(${e})[1]`)}return e}withinGroupSql(s){let t=s.args.this;if(t instanceof bi){let i=s.args.expression;if(!(i instanceof wt))return this.sql(t);let E=t.args.this;t.setArgKey("this",new wt({this:K(t.args.this,N)?.copy(),expressions:i.args.expressions}));let c=this.functionFallbackSql(t);return E instanceof N?this.addArrayAggNullFilter(c,t,E):""}let e=this.sql(s,"expression");if(t instanceof As||t instanceof xs){let i=s.find(nr);i&&(t.setArgKey("expression",t.args.this),t.setArgKey("this",i.args.this))}return`${this.sql(s,"this").replace(/\)$/,"")}${e})`}lengthSql(s){let t=s.args.this;if(!s.args.binary||t instanceof a&&t.isString)return this.func("LENGTH",[t]);if((t?.type?t:t&&Nt(t,{dialect:this.dialect}))?.isType(l.TEXT_TYPES))return this.func("LENGTH",[t]);let r=new T({this:t,to:new l({this:"varbinary"})}),i=new T({this:t,to:new l({this:"varchar"})}),E=new $({this:new d({this:"TYPEOF",expressions:t?[t]:[]})}).when(a.string("BLOB"),new ts({this:r})).else(new d({this:"LENGTH",expressions:[i]}));return this.sql(E)}levenshteinSql(s){ds.call(this,s,"insCost","delCost","subCost");let t=s.args.this,e=s.args.expression,r=s.args.maxDist;if(!r)return this.func("LEVENSHTEIN",[t,e]);let i=new fe({this:t,expression:e});return this.sql(new Qn({this:i,expressions:[r],ignoreNulls:!1}))}padSql(s){let t=s.args.this,e=s.args.fillPattern??a.string(" ");if(Z(t)||Z(e)){let r=s.args.expression,i=s.args.isLeft,E=new ts({this:t}),c=new F({this:r,expression:E}),u=new ue({this:a.number(0),expressions:[c],ignoreNulls:!0}),A=new me({this:e,times:[u]}),[_,O]=i?[A,t]:[t,A];return this.sql(new Cr({this:_,expression:O}))}return super.padSql(s)}minhashSql(s){let t=s.args.this,e=s.args.expressions??[];if(e.length!==1||e[0]instanceof Er)return this.unsupported("MINHASH with multiple expressions or * requires manual restructuring"),this.func("MINHASH",[t,...e]);let r=b(h.MINHASH_TEMPLATE.copy(),[],{expr:e[0],k:t});return`(${this.sql(r)})`}minhashCombineSql(s){let t=b(h.MINHASH_COMBINE_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}approximateSimilaritySql(s){let t=b(h.APPROXIMATE_SIMILARITY_TEMPLATE.copy(),[],{expr:s.args.this});return`(${this.sql(t)})`}arraySliceSql(s){let t=s.args.start,e=s.args.end;return s.args.zeroBased&&(t&&(t=J().when(new Mr({this:t.copy(),expression:a.number(0)}),new I({this:t.copy(),expression:a.number(1)}),{copy:!1}),t.setArgKey("default",s.args.start)),e&&(e=J().when(new ks({this:e.copy(),expression:a.number(0)}),new F({this:e.copy(),expression:a.number(1)}),{copy:!1}),e.setArgKey("default",s.args.end))),this.func("ARRAY_SLICE",[s.args.this,t,e,s.args.step])}arraysZipSql(s){let t=s.args.expressions??[];if(t.length===0)return this.sql(new W({expressions:[new Ae({keys:new W,values:new W})]}));let e=t.map(O=>new z({this:O})),r=e.length===1?e[0]:new ue({this:e[0],expressions:e.slice(1),ignoreNulls:!1}),i=new ft({expressions:t.map((O,G)=>new Lt({this:a.string(`$${G+1}`),expression:f()}))}),E=new I({this:new Ds({this:new It({this:"__i"})}),expression:a.number(1)}),c=new ft({expressions:t.map((O,G)=>new Lt({this:a.string(`$${G+1}`),expression:new q({this:new d({this:"COALESCE",expressions:[O,new W({})]}),expressions:[E.copy()]})}))}),u=Kt(t.map(O=>O.is(f()))),A=Vt(t.map(O=>new v({this:new z({this:O}),expression:a.number(0)}))),_=b(h.ARRAYS_ZIP_TEMPLATE.copy(),[],{nullCheck:u,allEmptyCheck:A,emptyStruct:i,maxLen:r,transformStruct:c});return this.sql(_)}lowerSql(s){let t=this.func("LOWER",[et(s.args.this)]);return ut.call(this,s,t)}upperSql(s){let t=this.func("UPPER",[et(s.args.this)]);return ut.call(this,s,t)}reverseSql(s){let t=this.func("REVERSE",[et(s.args.this)]);return ut.call(this,s,t)}randSql(s){s.args.this&&this.unsupported("RANDOM with seed is not supported in DuckDB");let e=s.args.lower,r=s.args.upper;if(e&&r){let i=new L({this:new F({this:r,expression:e})}),E=new I({this:e,expression:new gt({this:x("random"),expression:i})});return this.sql(ot(E,"bigint"))}return"RANDOM()"}rightSql(s){let t=s.args.this,e=s.args.expression;if(Z(t)){let r=new kn({this:t}),i=new gt({this:e,expression:a.number(2)});return`UNHEX(${this.func("RIGHT",[r,i])})`}return this.func("RIGHT",[t,e])}base64EncodeSql(s){let t=s.args.this;t?.isType(l.TEXT_TYPES)&&(t=new d({this:"ENCODE",expressions:[t]})),t=new Hn({this:t});let e=s.args.maxLineLength,r=s.args.alphabet;t=Jo(t,r);let i=e instanceof a&&e.isNumber?parseInt(e.args.this??"0"):0;if(0<i){let E=new Qr({expressions:[a.number(10)]});t=new xi({this:new ls({this:t,expression:a.string(`(.{${i}})`),replacement:new vt({expressions:[a.string("\\1"),E.copy()]})}),expression:E,position:"trailing"})}return this.sql(t)}replaceSql(s){let t=this.func("REPLACE",[et(s.args.this),et(s.args.expression),et(s.args.replacement)]);return ut.call(this,s,t)}bitwiseOp(s,t){ka(s);let e=this.binary(s,t);return ut.call(this,s,e)}bitwiseXorSql(s){ka(s);let t=this.func("XOR",[s.args.this,s.args.expression]);return ut.call(this,s,t)}objectInsertSql(s){let t=s.args.this,e=s.args.key,r=e instanceof N?e.name:"",i=this.sql(s,"value"),E=`${r} := ${i}`;return t instanceof ft&&(!t.args.expressions||t.args.expressions.length===0)?this.func("STRUCT_PACK",[E]):this.func("STRUCT_INSERT",[t,E])}mapCatSql(s){let t=b(h.MAPCAT_TEMPLATE.copy(),[],{map1:s.args.this,map2:s.args.expression});return this.sql(t)}mapDeleteSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Bs({this:H("x"),expression:H("key")}),i=new Ot({this:new zt({this:r,expressions:e})}),E=new rt({this:i,expressions:[H("x")]}),c=new rs({this:x("map_entries",t),expression:E}),u=x("map_from_entries",c);return this.sql(u)}mapSizeSql(s){return this.func("CARDINALITY",[s.args.this])}mapPickSql(s){let t=s.args.this,e=s.args.expressions??[],r=new Bs({this:H("x"),expression:H("key")}),i;e.length===1&&e[0].isType?.("array")?i=new rt({this:x("ARRAY_CONTAINS",e[0],r),expressions:[H("x")]}):i=new rt({this:new zt({this:r,expressions:e}),expressions:[H("x")]});let E=x("MAP_FROM_ENTRIES",x("LIST_FILTER",x("MAP_ENTRIES",t),i));return this.sql(E)}mapInsertSql(s){s.args.updateFlag&&this.unsupported("MAP_INSERT update_flag is not supported in DuckDB");let t=s.args.this,e=s.args.key,r=s.args.value;if(r!==void 0&&t){let u=t.type;if(u instanceof l&&u.args.expressions&&1<u.args.expressions.length){let A=u.args.expressions[1];r=ot(r,A)}}let i=new ft({expressions:[new Lt({this:e,expression:r})]}),E=new xe({this:i}),c=x("MAP_CONCAT",t,E);return this.sql(c)}startsWithSql(s){return this.func("STARTS_WITH",[et(s.args.this),et(s.args.expression)])}spaceSql(s){return this.sql(new me({this:a.string(" "),times:[new T({this:s.args.this,to:new l({this:"bigint"})})]}))}tableFromRowsSql(s){if(s.args.this instanceof $s){let t=new ys({this:s.args.this,alias:s.args.alias,joins:s.args.joins});return this.sql(t)}return super.tableFromRowsSql(s)}unnestSql(s){if(s.args.explodeArray){s.args.expressions||s.setArgKey("expressions",[]),s.args.expressions?.push(new vs({this:new C({this:"max_depth"}),expression:a.number(2)}));let e=s.args.alias;e instanceof Dt&&(s.setArgKey("alias",void 0),e.args.columns&&0<e.args.columns.length&&(e=new Dt({this:m(e.args.columns,0)})));let r=super.unnestSql(s),i=e?` AS ${this.sql(e)}`:"";return`(SELECT ${r})${i}`}return super.unnestSql(s)}ignoreNullsSql(s){let t=s.args.this;if(this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(r=>t instanceof r))return super.ignoreNullsSql(s);let e=t;return e instanceof Fi&&(e=new kt({this:e.args.this})),e instanceof kt||e instanceof Mi||this.unsupported("IGNORE NULLS is not supported for non-window functions."),this.sql(e)}splitSql(s){let t=x("STR_SPLIT",s.args.this,s.args.expression),e=J();e.setArgKey("default",t);let r=!1;return s.args.nullReturnsNull&&(e=e.when(new at({this:s.args.expression,expression:new it({})}),new it({}),{copy:!1}),r=!0),s.args.emptyDelimiterReturnsWhole&&(e=e.when(new v({this:s.args.expression.copy(),expression:a.string("")}),ea([s.args.this]),{copy:!1}),r=!0),this.sql(r?e:t)}splitPartSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){s.args.partIndexZeroAsOne&&(r=new L({this:J().when(new v({this:r.copy(),expression:a.number(0)}),a.number(1),{copy:!1})}),r.args.this.setArgKey("default",s.args.partIndex));let i=new d({this:"SPLIT_PART",expressions:[t,e,r].filter(Boolean)}),E=!1,c=J();if(c.setArgKey("default",i),s.args.emptyDelimiterReturnsWhole){let u=new L({this:J().when(new Xt({this:new v({this:r.copy(),expression:a.number(1)}),expression:new v({this:r.copy(),expression:a.number(-1)})}),t,{copy:!1})});u.args.this.setArgKey("default",a.string("")),c=c.when(new v({this:e.copy(),expression:a.string("")}),u,{copy:!1}),E=!0}return this.sql(E?c:i)}return this.functionFallbackSql(s)}respectNullsSql(s){return this._constructor.IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS.some(t=>s.args.this instanceof t)?super.respectNullsSql(s):(this.unsupported("RESPECT NULLS is not supported for non-window functions."),this.sql(s,"this"))}arrayToStringSql(s){let t=s.args.null;if(s.args.nullIsEmpty){let e=H("x"),r=new Ht({this:s.args.this.copy(),expression:new rt({this:new Yt({this:ot(e,"TEXT"),expressions:[a.string("")]}),expressions:[e]})}),i=new te({this:r,expression:s.args.expression});return s.args.nullDelimIsNull?this.sql(J().when(s.args.expression.copy().is(f()),f()).else(i)):this.sql(i)}if(t){let e=H("x");return this.sql(new te({this:new Ht({this:s.args.this,expression:new rt({this:new Yt({this:e,expressions:[t]}),expressions:[e]})}),expression:s.args.expression}))}return this.func("ARRAY_TO_STRING",[s.args.this,s.args.expression])}regexpExtractCommon(s){let t=s.args.this,e=s.args.group,r=s.args.parameters,i=s.args.position,E=s.args.occurrence,c="nullIfPosOverflow"in s.args?s.args.nullIfPosOverflow:void 0;r&&r.isString&&(r.name??"").includes("e")&&(r=a.string((r.name??"").replace(/e/g,"")));let u=this.validateRegexpFlags(r,"cims"),A=e,_=String(this.dialect._constructor.REGEXP_EXTRACT_DEFAULT_GROUP);!u&&e&&(e instanceof It&&e.name===_||e instanceof a&&String(e.args.this)===_)&&(A=void 0);let O=u?a.string(u):void 0;i&&(!(i instanceof a&&i.isInteger)||1<parseInt(i.args.this??"0"))&&(t=new Pt({this:t,start:i}),c&&(t=new he({this:t,expression:a.string("")})));let G=s instanceof Re,V=E&&(!(E instanceof a&&E.isInteger)||1<parseInt(E.args.this??"0")),Ls=G||V?"REGEXP_EXTRACT_ALL":"REGEXP_EXTRACT",Tt=new d({this:Ls,expressions:[t,s.args.expression,A,O].filter(Boolean)});return G&&V?Tt=new q({this:Tt,expressions:[new B({this:E})]}):V&&(Tt=new d({this:"ARRAY_EXTRACT",expressions:[Tt,E]})),this.sql(Tt)}regexpExtractSql(s){return this.regexpExtractCommon(s)}regexpExtractAllSql(s){return this.regexpExtractCommon(s)}numberToStrSql(s){if(s.args.culture)return this.unsupported("DuckDB does not support the culture argument in NumberToStr"),this.functionFallbackSql(s);let t=s.args.format?.name;return t&&/^\d+$/.test(t)?this.func("FORMAT",[a.string(`{:,.${t}f}`),s.args.this]):(this.unsupported("Only integer formats are supported by NumberToStr"),this.functionFallbackSql(s))}autoIncrementColumnConstraintSql(s){return this.unsupported("The AUTOINCREMENT column constraint is not supported by DuckDB"),""}aliasesSql(s){let t=s.args.this;return t instanceof ki?this.posexplodeSql(t):super.aliasesSql(s)}posexplodeSql(s){let t=s.args.this,e=s.parent,r=new It({this:"pos",quoted:!1}),i=new It({this:"col",quoted:!1});if(e instanceof cr){let A=e.args.expressions;r=A?.[0],i=A?.[1]}else if(e instanceof ys){let A=e.args.alias;if(A instanceof Dt){let _=A.args.columns;_&&0<_.length&&(r=_[0],i=_[1]??i),A.pop()}}let E=this.sql(new Es({expressions:[t],alias:i})),c=this.sql(new qs({this:new F({this:new d({this:"GENERATE_SUBSCRIPTS",expressions:[t,a.number(1)]}),expression:a.number(1)}),alias:r})),u=this.formatArgs([c,E]);return e instanceof Cs||e&&e.parent instanceof Cs?`(SELECT ${u})`:u}addMonthsSql(s){let t=s.args.this;t?.type||(t=t&&Nt(t,{dialect:this.dialect})),t?.isType(l.TEXT_TYPES)&&(t=new T({this:t,to:new l({this:"timestamp"})}));let e=s.args.expression,r=e?.type?e:e&&Nt(e,{dialect:this.dialect}),i;r?.isType(["float","double","decimal"])?i=new d({this:"TO_MONTHS",expressions:[new T({this:new d({this:"ROUND",expressions:e&&[e]}),to:new l({this:"int"})})]}):i=new Y({this:e,unit:new C({this:"MONTH"})});let E=new I({this:t,expression:i}),c=s.args.preserveEndOfMonth,u=E;return c&&(u=new $({}).when(new v({this:x("LAST_DAY",t),expression:t}),x("LAST_DAY",E)).else(E)),t?.isType(["date","timestamptz"])?this.sql(new T({this:u,to:t.type})):this.sql(u)}formatSql(s){return s.name.toLowerCase()==="%s"&&s.args.expressions?.length===1?this.func("FORMAT",[a.string("{}"),s.args.expressions[0]]):this.functionFallbackSql(s)}dateTruncSql(s){let t=s.args.unit,e=s.args.this,r=Qo(t),i=yt(s),E;return r?E=this.sql(ve(e,r,{preserveStartDay:!0})):E=this.func("DATE_TRUNC",[i,e]),s.args.inputTypePreserved&&e?.isType(l.TEMPORAL_TYPES)&&!(Os(i)&&e.isType("date"))?this.sql(new T({this:E,to:e.type})):E}timestampTruncSql(s){let t=yt(s),e=s.args.zone,r=s.args.this,i=Os(t);if(i&&e){r=new ct({this:r,zone:e});let c=this.func("DATE_TRUNC",[t,r]);return this.sql(new ct({this:c,zone:e}))}let E=this.func("DATE_TRUNC",[t,r]);if(s.args.inputTypePreserved){if(r?.isType(["time","timetz"])){let c=new T({this:a.string("1970-01-01"),to:new l({this:"date"})}),u=new I({this:c,expression:r});return E=this.func("DATE_TRUNC",[t,u]),this.sql(new T({this:E,to:r.type}))}if(r?.isType(l.TEMPORAL_TYPES)&&!(i&&r.isType("date")))return this.sql(new T({this:E,to:r.type}))}return E}trimSql(s){let t=et(s.args.this);if(t&&s.setArgKey("this",t),s.args.expression instanceof N){let r=et(s.args.expression);r&&s.setArgKey("expression",r)}let e=super.trimSql(s);return ut.call(this,s,e)}hexStringSql(s){return super.hexStringSql(s,{binaryFunctionRepr:"UNHEX"})}roundSql(s){let t=s.args.this,e=s.args.decimals,r=s.args.truncate;e&&s.args.castsNonIntegerDecimals&&(e.isInteger||e.isType([...l.INTEGER_TYPES])||(e=new T({this:e,to:new l({this:"int"})})));let i="ROUND";if(r instanceof a){let E=r.args.this?.toUpperCase();E!==void 0&&["ROUND_HALF_EVEN","HALF_TO_EVEN"].includes(E)?(i="ROUND_EVEN",r=void 0):E!==void 0&&["ROUND_HALF_AWAY_FROM_ZERO","HALF_AWAY_FROM_ZERO"].includes(E)&&(r=void 0)}return this.func(i,[t,e,r])}strPositionSql(s){let t=s.args.position;return s.args.clampPosition&&t&&(s=s.copy(),s.setArgKey("position",new Q({this:new qr({this:t,expression:a.number(0)}),true:a.number(1),false:t.copy()}))),ca.call(this,s)}strtokSql(s){let t=s.args.this,e=s.args.delimiter,r=s.args.partIndex;if(e&&r){let i=new d({this:"REGEXP_REPLACE",expressions:[e,a.string(String.raw`([\[\]^.\-*+?(){}|$\\])`),a.string(String.raw`\\\1`),a.string("g")]}),E=J().when(e.eq(a.string("")),a.string("")).else(x("CONCAT",a.string("["),i,a.string("]"))),c=x("REGEXP_SPLIT_TO_ARRAY",t,E),u=H("x"),A=u.eq(a.string("")),_=x("LIST_FILTER",c,new rt({this:new Ot({this:A.copy()}),expressions:[u.copy()]})),O=new q({this:_,expressions:[r],offset:1}),G=b(this._constructor.STRTOK_TEMPLATE.copy(),[],{string:t,delimiter:e,partIndex:r,baseFunc:O});return this.sql(G)}return this.functionFallbackSql(s)}approxQuantileSql(s){let t=this.func("APPROX_QUANTILE",[s.args.this,s.args.quantile]);return s.isType(l.REAL_TYPES)&&(t=`CAST(${t} AS DOUBLE)`),t}approxQuantilesSql(s){let t=s.args.this,e;if(t instanceof bs){if(!t.args.expressions||t.args.expressions.length<2)return this.unsupported("APPROX_QUANTILES requires a bucket count argument"),this.functionFallbackSql(s);e=t.args.expressions[1].pop()}else e=s.args.expression;if(!(e instanceof a&&e.isInteger))return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let r=parseInt(e.args.this??"0");if(r<=0)return this.unsupported("APPROX_QUANTILES bucket count must be a positive integer"),this.functionFallbackSql(s);let i=Array.from({length:r+1},(E,c)=>a.number(c/r));return this.sql(new zi({this:t,quantile:new W({expressions:i})}))}jsonExtractScalarSql(s){return s.args.scalarOnly&&(s=new ge({this:new d({this:"JSON_VALUE",expressions:[s.args.this,s.args.expression].filter(t=>t instanceof N)}),expression:a.string("$")})),Ha.call(this,s)}bitwiseNotSql(s){let t=s.args.this;Z(t)&&(s.type=new l({this:"binary"}));let e=Xe(t);t instanceof br&&(e=new L({this:e})),s.setArgKey("this",e);let r=`~${this.sql(s,"this")}`;return ut.call(this,s,r)}windowSql(s){let t=s.args.this;return t instanceof At||t instanceof Gt&&t.args.this instanceof At?this.corrSql(s):super.windowSql(s)}filterSql(s){return s.args.this instanceof At?this.corrSql(s):super.filterSql(s)}corrSql(s){if(s instanceof At&&!s.args.nullOnZeroVariance)return this.func("CORR",[s.args.this,s.args.expression]);let t=CE(s);return t?this.sql(new $({}).when(new Te({this:t}),f()).else(t)):s instanceof jt?super.windowSql(s):s instanceof Gt?super.filterSql(s):this.sql(s)}};w=Mt(vo),S(w,10,"STRTOK_TEMPLATE",Yo,h),S(w,10,"AFTER_HAVING_MODIFIER_TRANSFORMS",Bo,h),S(w,10,"STRUCT_DELIMITER",Ho,h),S(w,10,"ORIGINAL_TRANSFORMS",Uo,h),S(w,10,"SUPPORTED_JSON_PATH_PARTS",Fo,h),S(w,10,"TYPE_MAPPING",Go,h),S(w,10,"RESERVED_KEYWORDS",Do,h),S(w,10,"UNWRAPPED_INTERVAL_VALUES",bo,h),S(w,10,"PROPERTIES_LOCATION",qo,h),S(w,10,"IGNORE_RESPECT_NULLS_WINDOW_FUNCTIONS",Mo,h),S(w,10,"ZIPF_TEMPLATE",yo,h),S(w,10,"NORMAL_TEMPLATE",Co,h),S(w,10,"SEEDED_RANDOM_TEMPLATE",Po,h),S(w,10,"SEQ_UNSIGNED",Oo,h),S(w,10,"SEQ_SIGNED",Lo,h),S(w,10,"MAPCAT_TEMPLATE",_o,h),S(w,10,"EXTRACT_STRFTIME_MAPPINGS",wo,h),S(w,10,"EXTRACT_EPOCH_MAPPINGS",Io,h),S(w,10,"BITMAP_CONSTRUCT_AGG_TEMPLATE",No,h),S(w,10,"RANDSTR_TEMPLATE",mo,h),S(w,10,"MINHASH_TEMPLATE",Ro,h),S(w,10,"MINHASH_COMBINE_TEMPLATE",xo,h),S(w,10,"APPROXIMATE_SIMILARITY_TEMPLATE",Ao,h),S(w,10,"ARRAYS_ZIP_TEMPLATE",fo,h),qt(w,h),bt(w,3,h),p(h,"DuckDBGenerator"),h.SUPPORTS_DECODE_CASE=!1,h.SELECT_KINDS=[],h.PARAMETER_TOKEN="$",h.NAMED_PLACEHOLDER_TOKEN="$",h.JOIN_HINTS=!1,h.TABLE_HINTS=!1,h.QUERY_HINTS=!1,h.LIMIT_FETCH="LIMIT",h.RENAME_TABLE_WITH_DB=!1,h.NVL2_SUPPORTED=!1,h.SEMI_ANTI_JOIN_WITH_SIDE=!1,h.TABLESAMPLE_KEYWORDS="USING SAMPLE",h.TABLESAMPLE_SEED_KEYWORD="REPEATABLE",h.LAST_DAY_SUPPORTS_DATE_PART=!1,h.JSON_KEY_VALUE_PAIR_SEP=",",h.IGNORE_NULLS_IN_FUNC=!0,h.IGNORE_NULLS_BEFORE_ORDER=!1,h.JSON_PATH_BRACKETED_KEY_SUPPORTED=!1,h.SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY=!1,h.SUPPORTS_CREATE_TABLE_LIKE=!1,h.MULTI_ARG_DISTINCT=!1,h.CAN_IMPLEMENT_ARRAY_ANY=!0,h.SUPPORTS_TO_NUMBER=!1,h.SUPPORTS_WINDOW_EXCLUDE=!0,h.COPY_HAS_INTO_KEYWORD=!1,h.STAR_EXCEPT="EXCLUDE",h.PAD_FILL_PATTERN_IS_REQUIRED=!0,h.ARRAY_SIZE_DIM_REQUIRED=!1,h.NORMALIZE_EXTRACT_DATE_PARTS=!0,h.SUPPORTS_LIKE_QUANTIFIERS=!1,h.SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD=!0,h.ARRAY_BAG_TEMPLATE=y(`CASE
|
|
86
95
|
WHEN :arr1 IS NULL OR :arr2 IS NULL THEN NULL
|
|
87
96
|
ELSE LIST_TRANSFORM(
|
|
88
97
|
LIST_FILTER(
|
|
@@ -91,11 +100,11 @@ import{a as Ca}from"../chunk-3OVM5ZRR.js";import"../chunk-KNRQDMQ7.js";import{$d
|
|
|
91
100
|
),
|
|
92
101
|
pair -> pair[0]
|
|
93
102
|
)
|
|
94
|
-
END`),
|
|
103
|
+
END`),h.ARRAY_EXCEPT_CONDITION=y("LEN(LIST_FILTER(:arr1[1:pair[1]], e -> e IS NOT DISTINCT FROM pair[0])) > LEN(LIST_FILTER(:arr2, e -> e IS NOT DISTINCT FROM pair[0]))"),h.ARRAY_INTERSECTION_CONDITION=y("LEN(LIST_FILTER(:arr1[1:pair[1]], e -> e IS NOT DISTINCT FROM pair[0])) <= LEN(LIST_FILTER(:arr2, e -> e IS NOT DISTINCT FROM pair[0]))"),h.ARRAY_EXCEPT_SET_TEMPLATE=y(`CASE
|
|
95
104
|
WHEN :arr1 IS NULL OR :arr2 IS NULL THEN NULL
|
|
96
105
|
ELSE LIST_FILTER(
|
|
97
106
|
LIST_DISTINCT(:arr1),
|
|
98
107
|
e -> LEN(LIST_FILTER(:arr2, x -> x IS NOT DISTINCT FROM e)) = 0
|
|
99
108
|
)
|
|
100
|
-
END`);var
|
|
109
|
+
END`);var $t=h,ko,Xo,Vo,Ko,Wo,$o,Rt,P=class P extends($o=De,Wo=[g],Ko=[g],Vo=[g],Xo=[g],ko=[g],$o){static get NULL_ORDERING(){return"nulls_are_last"}static get NORMALIZATION_STRATEGY(){return"caseInsensitive"}static get DATE_PART_MAPPING(){let s={...De.DATE_PART_MAPPING,DAYOFWEEKISO:"ISODOW"};return delete s.WEEKDAY,s}static get EXPRESSION_METADATA(){return new Map(ya.EXPRESSION_METADATA)}static get INVERSE_TIME_MAPPING(){return{"%e":"%-d","%:z":"%z","%-z":"%z","%f_zero":"%n","%f_one":"%n","%f_two":"%n","%f_three":"%g","%f_four":"%n","%f_five":"%n","%f_seven":"%n","%f_eight":"%n","%f_nine":"%n"}}toJsonPath(s){if(s instanceof a&&s.isString){let t=s.name;if(t.startsWith("/")||t.includes("[#"))return s}return super.toJsonPath(s)}};Rt=Mt($o),S(Rt,10,"NULL_ORDERING",Wo,P),S(Rt,10,"NORMALIZATION_STRATEGY",Ko,P),S(Rt,10,"DATE_PART_MAPPING",Vo,P),S(Rt,10,"EXPRESSION_METADATA",Xo,P),S(Rt,10,"INVERSE_TIME_MAPPING",ko,P),qt(Rt,P),bt(Rt,3,P),p(P,"DuckDB"),P.DIALECT_NAME="duckdb",P.SUPPORTS_USER_DEFINED_TYPES=!0,P.SAFE_DIVISION=!0,P.INDEX_OFFSET=1,P.CONCAT_COALESCE=!0,P.SUPPORTS_ORDER_BY_ALL=!0,P.SUPPORTS_FIXED_SIZE_ARRAYS=!0,P.STRICT_JSON_PATH_SYNTAX=!1,P.NUMBERS_CAN_BE_UNDERSCORE_SEPARATED=!0,P.Tokenizer=Ve,P.Parser=Ke,P.Generator=$t;var _s=P;export{_s as DuckDB,iE as MAX_BIT_POSITION,rE as RANDSTR_CHAR_POOL,nE as RANDSTR_SEED,Ma as REGEX_ESCAPE_REPLACEMENTS,aE as SEQ_BASE,EE as SEQ_RESTRICTED,eE as TIMEZONE_PATTERN,ws as WEEK_START_DAY_TO_DOW,ms as WS_CONTROL_CHARS_TO_DUCK};
|
|
101
110
|
//# sourceMappingURL=duckdb.js.map
|