@malloydata/render 0.0.126-dev240221165840 → 0.0.126

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.
@@ -1572,8 +1572,8 @@
1572
1572
  var util_1 = require_util();
1573
1573
  function fnConcat() {
1574
1574
  return [
1575
- // TODO in DuckDB, nulls are treated like "", but in BigQuery, nulls propagate and the
1576
- // result becomes null
1575
+ // TODO: in DuckDB and Postgres, nulls are treated like "",
1576
+ // but in BigQuery and Snowflake, nulls propagate and the result becomes null
1577
1577
  (0, util_1.overload)((0, util_1.minScalar)("string"), [], [{ type: "dialect", function: "stringLiteral", literal: "" }]),
1578
1578
  (0, util_1.overload)((0, util_1.minScalar)("string"), [
1579
1579
  (0, util_1.params)("values", (0, util_1.anyExprType)("string"), (0, util_1.anyExprType)("number"), (0, util_1.anyExprType)("date"), (0, util_1.anyExprType)("timestamp"), (0, util_1.anyExprType)("boolean"))
@@ -4733,6 +4733,691 @@ ${hackSplitComment}
4733
4733
  }
4734
4734
  });
4735
4735
 
4736
+ // ../malloy/dist/dialect/snowflake/functions/chr.js
4737
+ var require_chr3 = __commonJS({
4738
+ "../malloy/dist/dialect/snowflake/functions/chr.js"(exports) {
4739
+ "use strict";
4740
+ Object.defineProperty(exports, "__esModule", { value: true });
4741
+ exports.fnChr = void 0;
4742
+ var util_1 = require_util();
4743
+ function fnChr() {
4744
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("number"));
4745
+ return [
4746
+ (0, util_1.overload)(
4747
+ (0, util_1.minScalar)("string"),
4748
+ [value3.param],
4749
+ // Need to explicitly have a case for when the arg is 0, to return ''
4750
+ (0, util_1.sql)`COALESCE(CHR(${value3.arg}), '')`
4751
+ )
4752
+ ];
4753
+ }
4754
+ exports.fnChr = fnChr;
4755
+ }
4756
+ });
4757
+
4758
+ // ../malloy/dist/dialect/snowflake/functions/div.js
4759
+ var require_div3 = __commonJS({
4760
+ "../malloy/dist/dialect/snowflake/functions/div.js"(exports) {
4761
+ "use strict";
4762
+ Object.defineProperty(exports, "__esModule", { value: true });
4763
+ exports.fnDiv = void 0;
4764
+ var util_1 = require_util();
4765
+ function fnDiv() {
4766
+ const dividend = (0, util_1.makeParam)("dividend", (0, util_1.anyExprType)("number"));
4767
+ const divisor = (0, util_1.makeParam)("divisor", (0, util_1.anyExprType)("number"));
4768
+ return [
4769
+ (0, util_1.overload)(
4770
+ (0, util_1.minScalar)("number"),
4771
+ [dividend.param, divisor.param],
4772
+ // in Snowflake division is always a float division, so we need this conversion
4773
+ (0, util_1.sql)`CASE WHEN DIV0(${dividend.arg}, ${divisor.arg}) < 0 THEN CEIL(DIV0(${dividend.arg}, ${divisor.arg})) ELSE FLOOR(DIV0(${dividend.arg}, ${divisor.arg})) END`
4774
+ )
4775
+ ];
4776
+ }
4777
+ exports.fnDiv = fnDiv;
4778
+ }
4779
+ });
4780
+
4781
+ // ../malloy/dist/dialect/snowflake/functions/is_inf.js
4782
+ var require_is_inf4 = __commonJS({
4783
+ "../malloy/dist/dialect/snowflake/functions/is_inf.js"(exports) {
4784
+ "use strict";
4785
+ Object.defineProperty(exports, "__esModule", { value: true });
4786
+ exports.fnIsInf = void 0;
4787
+ var util_1 = require_util();
4788
+ function fnIsInf() {
4789
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("number"));
4790
+ return [
4791
+ (0, util_1.overload)((0, util_1.minScalar)("boolean"), [value3.param], (0, util_1.sql)`COALESCE(${value3.arg} = 'inf'::FLOAT OR ${value3.arg} = '-inf'::FLOAT, false)`)
4792
+ ];
4793
+ }
4794
+ exports.fnIsInf = fnIsInf;
4795
+ }
4796
+ });
4797
+
4798
+ // ../malloy/dist/dialect/snowflake/functions/is_nan.js
4799
+ var require_is_nan4 = __commonJS({
4800
+ "../malloy/dist/dialect/snowflake/functions/is_nan.js"(exports) {
4801
+ "use strict";
4802
+ Object.defineProperty(exports, "__esModule", { value: true });
4803
+ exports.fnIsNan = void 0;
4804
+ var util_1 = require_util();
4805
+ function fnIsNan() {
4806
+ return [
4807
+ (0, util_1.overload)((0, util_1.minScalar)("boolean"), [(0, util_1.param)("value", (0, util_1.anyExprType)("number"))], (0, util_1.sql)`COALESCE(${(0, util_1.arg)("value")} = 'NAN'::FLOAT, false)`)
4808
+ ];
4809
+ }
4810
+ exports.fnIsNan = fnIsNan;
4811
+ }
4812
+ });
4813
+
4814
+ // ../malloy/dist/dialect/snowflake/functions/length.js
4815
+ var require_length2 = __commonJS({
4816
+ "../malloy/dist/dialect/snowflake/functions/length.js"(exports) {
4817
+ "use strict";
4818
+ Object.defineProperty(exports, "__esModule", { value: true });
4819
+ exports.fnByteLength = exports.fnLength = void 0;
4820
+ var util_1 = require_util();
4821
+ function fnLength() {
4822
+ return [
4823
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [(0, util_1.param)("value", (0, util_1.anyExprType)("string"))], (0, util_1.sql)`LENGTH(${(0, util_1.arg)("value")})`)
4824
+ ];
4825
+ }
4826
+ exports.fnLength = fnLength;
4827
+ function fnByteLength() {
4828
+ return [
4829
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [(0, util_1.param)("value", (0, util_1.anyExprType)("string"))], (0, util_1.sql)`CEIL(BIT_LENGTH(${(0, util_1.arg)("value")}) / 8)`)
4830
+ ];
4831
+ }
4832
+ exports.fnByteLength = fnByteLength;
4833
+ }
4834
+ });
4835
+
4836
+ // ../malloy/dist/dialect/snowflake/functions/log.js
4837
+ var require_log4 = __commonJS({
4838
+ "../malloy/dist/dialect/snowflake/functions/log.js"(exports) {
4839
+ "use strict";
4840
+ Object.defineProperty(exports, "__esModule", { value: true });
4841
+ exports.fnLog = void 0;
4842
+ var util_1 = require_util();
4843
+ function fnLog() {
4844
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("number"));
4845
+ const base2 = (0, util_1.makeParam)("base", (0, util_1.anyExprType)("number"));
4846
+ return [
4847
+ (0, util_1.overload)(
4848
+ (0, util_1.minScalar)("number"),
4849
+ [value3.param, base2.param],
4850
+ // Snowflake take base first, then value
4851
+ (0, util_1.sql)`LOG(${base2.arg}, ${value3.arg})`
4852
+ )
4853
+ ];
4854
+ }
4855
+ exports.fnLog = fnLog;
4856
+ }
4857
+ });
4858
+
4859
+ // ../malloy/dist/dialect/snowflake/functions/rand.js
4860
+ var require_rand4 = __commonJS({
4861
+ "../malloy/dist/dialect/snowflake/functions/rand.js"(exports) {
4862
+ "use strict";
4863
+ Object.defineProperty(exports, "__esModule", { value: true });
4864
+ exports.fnRand = void 0;
4865
+ var util_1 = require_util();
4866
+ function fnRand() {
4867
+ return [
4868
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [], (0, util_1.sql)`UNIFORM(0::FLOAT, 1::FLOAT, RANDOM())`)
4869
+ ];
4870
+ }
4871
+ exports.fnRand = fnRand;
4872
+ }
4873
+ });
4874
+
4875
+ // ../malloy/dist/dialect/snowflake/functions/regexp_extract.js
4876
+ var require_regexp_extract3 = __commonJS({
4877
+ "../malloy/dist/dialect/snowflake/functions/regexp_extract.js"(exports) {
4878
+ "use strict";
4879
+ Object.defineProperty(exports, "__esModule", { value: true });
4880
+ exports.fnRegexpExtract = void 0;
4881
+ var util_1 = require_util();
4882
+ function fnRegexpExtract() {
4883
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("string"));
4884
+ const pattern = (0, util_1.makeParam)("pattern", (0, util_1.anyExprType)("regular expression"));
4885
+ return [
4886
+ (0, util_1.overload)((0, util_1.minScalar)("string"), [value3.param, pattern.param], (0, util_1.sql)`REGEXP_SUBSTR(${value3.arg}, ${pattern.arg}, 1, 1, 'e')`)
4887
+ ];
4888
+ }
4889
+ exports.fnRegexpExtract = fnRegexpExtract;
4890
+ }
4891
+ });
4892
+
4893
+ // ../malloy/dist/dialect/snowflake/functions/starts_ends_with.js
4894
+ var require_starts_ends_with2 = __commonJS({
4895
+ "../malloy/dist/dialect/snowflake/functions/starts_ends_with.js"(exports) {
4896
+ "use strict";
4897
+ Object.defineProperty(exports, "__esModule", { value: true });
4898
+ exports.fnEndsWith = exports.fnStartsWith = void 0;
4899
+ var util_1 = require_util();
4900
+ function fnStartsWith() {
4901
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("string"));
4902
+ const prefix = (0, util_1.makeParam)("prefix", (0, util_1.anyExprType)("string"));
4903
+ return [
4904
+ (0, util_1.overload)((0, util_1.minScalar)("boolean"), [value3.param, prefix.param], (0, util_1.sql)`COALESCE(STARTSWITH(${value3.arg}, ${prefix.arg}), false)`)
4905
+ ];
4906
+ }
4907
+ exports.fnStartsWith = fnStartsWith;
4908
+ function fnEndsWith() {
4909
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("string"));
4910
+ const suffix = (0, util_1.makeParam)("suffix", (0, util_1.anyExprType)("string"));
4911
+ return [
4912
+ (0, util_1.overload)((0, util_1.minScalar)("boolean"), [value3.param, suffix.param], (0, util_1.sql)`COALESCE(ENDSWITH(${value3.arg}, ${suffix.arg}), false)`)
4913
+ ];
4914
+ }
4915
+ exports.fnEndsWith = fnEndsWith;
4916
+ }
4917
+ });
4918
+
4919
+ // ../malloy/dist/dialect/snowflake/functions/strpos.js
4920
+ var require_strpos2 = __commonJS({
4921
+ "../malloy/dist/dialect/snowflake/functions/strpos.js"(exports) {
4922
+ "use strict";
4923
+ Object.defineProperty(exports, "__esModule", { value: true });
4924
+ exports.fnStrpos = void 0;
4925
+ var util_1 = require_util();
4926
+ function fnStrpos() {
4927
+ const testString = (0, util_1.makeParam)("test_string", (0, util_1.anyExprType)("string"));
4928
+ const searchString = (0, util_1.makeParam)("search_string", (0, util_1.anyExprType)("string"));
4929
+ return [
4930
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [testString.param, searchString.param], (0, util_1.sql)`POSITION(${searchString.arg}, ${testString.arg})`)
4931
+ ];
4932
+ }
4933
+ exports.fnStrpos = fnStrpos;
4934
+ }
4935
+ });
4936
+
4937
+ // ../malloy/dist/dialect/snowflake/functions/trunc.js
4938
+ var require_trunc4 = __commonJS({
4939
+ "../malloy/dist/dialect/snowflake/functions/trunc.js"(exports) {
4940
+ "use strict";
4941
+ Object.defineProperty(exports, "__esModule", { value: true });
4942
+ exports.fnTrunc = void 0;
4943
+ var util_1 = require_util();
4944
+ function fnTrunc() {
4945
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.anyExprType)("number"));
4946
+ const precision = (0, util_1.makeParam)("precision", (0, util_1.anyExprType)("number"));
4947
+ return [
4948
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [value3.param], (0, util_1.sql)`CASE WHEN ${value3.arg} < 0 THEN CEIL(${value3.arg}) ELSE FLOOR(${value3.arg}) END`),
4949
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [value3.param, precision.param], (0, util_1.sql)`CASE WHEN ${value3.arg} < 0 THEN CEIL(${value3.arg} * POW(10, ${precision.arg})) / POW(10, ${precision.arg}) ELSE FLOOR(${value3.arg} * POW(10, ${precision.arg})) / POW(10, ${precision.arg}) END`)
4950
+ ];
4951
+ }
4952
+ exports.fnTrunc = fnTrunc;
4953
+ }
4954
+ });
4955
+
4956
+ // ../malloy/dist/dialect/snowflake/functions/string_agg.js
4957
+ var require_string_agg4 = __commonJS({
4958
+ "../malloy/dist/dialect/snowflake/functions/string_agg.js"(exports) {
4959
+ "use strict";
4960
+ Object.defineProperty(exports, "__esModule", { value: true });
4961
+ exports.fnStringAggDistinct = exports.fnStringAgg = void 0;
4962
+ var util_1 = require_util();
4963
+ function fnStringAgg() {
4964
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.maxScalar)("string"));
4965
+ const separator = (0, util_1.makeParam)("separator", (0, util_1.literal)((0, util_1.maxScalar)("string")));
4966
+ const orderBy = { type: "aggregate_order_by" };
4967
+ return [
4968
+ (0, util_1.overload)((0, util_1.minAggregate)("string"), [value3.param], (0, util_1.sql)`LISTAGG(${value3.arg}, ',') WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false }),
4969
+ (0, util_1.overload)((0, util_1.minAggregate)("string"), [value3.param, separator.param], (0, util_1.sql)`LISTAGG(${value3.arg}, ${separator.arg}) WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false })
4970
+ ];
4971
+ }
4972
+ exports.fnStringAgg = fnStringAgg;
4973
+ function fnStringAggDistinct() {
4974
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.maxScalar)("string"));
4975
+ const separator = (0, util_1.makeParam)("separator", (0, util_1.literal)((0, util_1.maxScalar)("string")));
4976
+ const orderBy = { type: "aggregate_order_by" };
4977
+ return [
4978
+ (0, util_1.overload)((0, util_1.minAggregate)("string"), [value3.param], (0, util_1.sql)`LISTAGG(DISTINCT ${value3.arg}, ',') WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false }),
4979
+ (0, util_1.overload)((0, util_1.minAggregate)("string"), [value3.param, separator.param], (0, util_1.sql)`LISTAGG(DISTINCT ${value3.arg}, ${separator.arg}) WITHIN GROUP(${orderBy})`, { supportsOrderBy: true, supportsLimit: false })
4980
+ ];
4981
+ }
4982
+ exports.fnStringAggDistinct = fnStringAggDistinct;
4983
+ }
4984
+ });
4985
+
4986
+ // ../malloy/dist/dialect/snowflake/functions/snowflake_functions.js
4987
+ var require_snowflake_functions = __commonJS({
4988
+ "../malloy/dist/dialect/snowflake/functions/snowflake_functions.js"(exports) {
4989
+ "use strict";
4990
+ Object.defineProperty(exports, "__esModule", { value: true });
4991
+ exports.SNOWFLAKE_FUNCTIONS = void 0;
4992
+ var functions_1 = require_functions();
4993
+ var chr_1 = require_chr3();
4994
+ var div_1 = require_div3();
4995
+ var is_inf_1 = require_is_inf4();
4996
+ var is_nan_1 = require_is_nan4();
4997
+ var length_1 = require_length2();
4998
+ var log_1 = require_log4();
4999
+ var rand_1 = require_rand4();
5000
+ var regexp_extract_1 = require_regexp_extract3();
5001
+ var starts_ends_with_1 = require_starts_ends_with2();
5002
+ var strpos_1 = require_strpos2();
5003
+ var trunc_1 = require_trunc4();
5004
+ var string_agg_1 = require_string_agg4();
5005
+ exports.SNOWFLAKE_FUNCTIONS = functions_1.FUNCTIONS.clone();
5006
+ exports.SNOWFLAKE_FUNCTIONS.add("byte_length", length_1.fnByteLength);
5007
+ exports.SNOWFLAKE_FUNCTIONS.add("chr", chr_1.fnChr);
5008
+ exports.SNOWFLAKE_FUNCTIONS.add("div", div_1.fnDiv);
5009
+ exports.SNOWFLAKE_FUNCTIONS.add("is_inf", is_inf_1.fnIsInf);
5010
+ exports.SNOWFLAKE_FUNCTIONS.add("is_nan", is_nan_1.fnIsNan);
5011
+ exports.SNOWFLAKE_FUNCTIONS.add("length", length_1.fnLength);
5012
+ exports.SNOWFLAKE_FUNCTIONS.add("log", log_1.fnLog);
5013
+ exports.SNOWFLAKE_FUNCTIONS.add("rand", rand_1.fnRand);
5014
+ exports.SNOWFLAKE_FUNCTIONS.add("regexp_extract", regexp_extract_1.fnRegexpExtract);
5015
+ exports.SNOWFLAKE_FUNCTIONS.add("starts_with", starts_ends_with_1.fnStartsWith);
5016
+ exports.SNOWFLAKE_FUNCTIONS.add("ends_with", starts_ends_with_1.fnEndsWith);
5017
+ exports.SNOWFLAKE_FUNCTIONS.add("strpos", strpos_1.fnStrpos);
5018
+ exports.SNOWFLAKE_FUNCTIONS.add("trunc", trunc_1.fnTrunc);
5019
+ exports.SNOWFLAKE_FUNCTIONS.add("string_agg", string_agg_1.fnStringAgg);
5020
+ exports.SNOWFLAKE_FUNCTIONS.add("string_agg_distinct", string_agg_1.fnStringAggDistinct);
5021
+ exports.SNOWFLAKE_FUNCTIONS.seal();
5022
+ }
5023
+ });
5024
+
5025
+ // ../malloy/dist/dialect/snowflake/functions/index.js
5026
+ var require_functions5 = __commonJS({
5027
+ "../malloy/dist/dialect/snowflake/functions/index.js"(exports) {
5028
+ "use strict";
5029
+ Object.defineProperty(exports, "__esModule", { value: true });
5030
+ exports.SNOWFLAKE_FUNCTIONS = void 0;
5031
+ var snowflake_functions_1 = require_snowflake_functions();
5032
+ Object.defineProperty(exports, "SNOWFLAKE_FUNCTIONS", { enumerable: true, get: function() {
5033
+ return snowflake_functions_1.SNOWFLAKE_FUNCTIONS;
5034
+ } });
5035
+ }
5036
+ });
5037
+
5038
+ // ../malloy/dist/dialect/snowflake/snowflake.js
5039
+ var require_snowflake = __commonJS({
5040
+ "../malloy/dist/dialect/snowflake/snowflake.js"(exports) {
5041
+ "use strict";
5042
+ Object.defineProperty(exports, "__esModule", { value: true });
5043
+ exports.SnowflakeDialect = void 0;
5044
+ var utils_1 = require_utils();
5045
+ var malloy_types_1 = require_malloy_types();
5046
+ var functions_1 = require_functions5();
5047
+ var dialect_1 = require_dialect();
5048
+ var extractionMap = {
5049
+ "day_of_week": "dayofweek",
5050
+ "day_of_year": "dayofyear"
5051
+ };
5052
+ var snowflakeToMalloyTypes = {
5053
+ // string
5054
+ "varchar": { type: "string" },
5055
+ "text": { type: "string" },
5056
+ "string": { type: "string" },
5057
+ "char": { type: "string" },
5058
+ "character": { type: "string" },
5059
+ "nvarchar": { type: "string" },
5060
+ "nvarchar2": { type: "string" },
5061
+ "char varying": { type: "string" },
5062
+ "nchar varying": { type: "string" },
5063
+ // numbers
5064
+ "number": { type: "number", numberType: "integer" },
5065
+ "numeric": { type: "number", numberType: "integer" },
5066
+ "decimal": { type: "number", numberType: "integer" },
5067
+ "dec": { type: "number", numberType: "integer" },
5068
+ "integer": { type: "number", numberType: "integer" },
5069
+ "int": { type: "number", numberType: "integer" },
5070
+ "bigint": { type: "number", numberType: "integer" },
5071
+ "smallint": { type: "number", numberType: "integer" },
5072
+ "tinyint": { type: "number", numberType: "integer" },
5073
+ "byteint": { type: "number", numberType: "integer" },
5074
+ "float": { type: "number", numberType: "float" },
5075
+ "float4": { type: "number", numberType: "float" },
5076
+ "float8": { type: "number", numberType: "float" },
5077
+ "double": { type: "number", numberType: "float" },
5078
+ "double precision": { type: "number", numberType: "float" },
5079
+ "real": { type: "number", numberType: "float" },
5080
+ "boolean": { type: "boolean" },
5081
+ // time and date
5082
+ "date": { type: "date" },
5083
+ "timestamp": { type: "timestamp" },
5084
+ "timestampntz": { type: "timestamp" },
5085
+ "timestamp_ntz": { type: "timestamp" },
5086
+ "timestamp without time zone": { type: "timestamp" },
5087
+ "timestamptz": { type: "timestamp" },
5088
+ "timestamp_tz": { type: "timestamp" },
5089
+ "timestamp with time zone": { type: "timestamp" }
5090
+ /* timestamp_ltz is not supported in malloy snowflake dialect */
5091
+ };
5092
+ var SnowflakeDialect = class extends dialect_1.Dialect {
5093
+ constructor() {
5094
+ super(...arguments);
5095
+ this.name = "snowflake";
5096
+ this.defaultNumberType = "NUMBER";
5097
+ this.defaultDecimalType = "NUMBER";
5098
+ this.udfPrefix = "__udf";
5099
+ this.hasFinalStage = false;
5100
+ this.divisionIsInteger = false;
5101
+ this.supportsSumDistinctFunction = false;
5102
+ this.defaultSampling = { rows: 5e4 };
5103
+ this.globalFunctions = functions_1.SNOWFLAKE_FUNCTIONS;
5104
+ this.unnestWithNumbers = false;
5105
+ this.supportUnnestArrayAgg = false;
5106
+ this.supportsAggDistinct = false;
5107
+ this.supportsCTEinCoorelatedSubQueries = false;
5108
+ this.supportsSafeCast = false;
5109
+ this.dontUnionIndex = false;
5110
+ this.supportsQualify = false;
5111
+ this.supportsNesting = true;
5112
+ }
5113
+ // don't mess with the table pathing.
5114
+ quoteTablePath(tablePath) {
5115
+ return tablePath;
5116
+ }
5117
+ sqlGroupSetTable(groupSetCount) {
5118
+ return `CROSS JOIN (SELECT seq4() as group_set FROM TABLE(GENERATOR(ROWCOUNT => ${groupSetCount + 1}))) as group_set`;
5119
+ }
5120
+ /*
5121
+ // this just returns null in snowflake
5122
+ select
5123
+ any_value (t is not null) as av
5124
+ from
5125
+ (
5126
+ select
5127
+ case
5128
+ when group_set = 1 then 'one'
5129
+ end as t
5130
+ from
5131
+ (
5132
+ SELECT
5133
+ seq4 () as group_set
5134
+ FROM
5135
+ TABLE (GENERATOR (ROWCOUNT => 3))
5136
+ ) as tbl
5137
+ );
5138
+ */
5139
+ sqlAnyValue(groupSet, fieldName) {
5140
+ return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN ${fieldName} END) WITHIN GROUP (ORDER BY ${fieldName} ASC NULLS LAST))[0]`;
5141
+ }
5142
+ mapFields(fieldList) {
5143
+ return fieldList.map((f4) => `
5144
+ ${f4.sqlExpression} as ${f4.sqlOutputName}`).join(", ");
5145
+ }
5146
+ mapFieldsForObjectConstruct(fieldList) {
5147
+ return fieldList.map((f4) => `'${f4.rawName}', (${f4.sqlExpression})`).join(", ");
5148
+ }
5149
+ sqlAggregateTurtle(groupSet, fieldList, orderBy, limit) {
5150
+ const fields = this.mapFieldsForObjectConstruct(fieldList);
5151
+ const orderByClause = orderBy ? ` WITHIN GROUP (${orderBy})` : "";
5152
+ const aggClause = `ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT(${fields}) END)${orderByClause}`;
5153
+ if (limit === void 0) {
5154
+ return `COALESCE(${aggClause}, [])`;
5155
+ }
5156
+ return `COALESCE(ARRAY_SLICE(${aggClause}, 0, ${limit}), [])`;
5157
+ }
5158
+ sqlAnyValueTurtle(groupSet, fieldList) {
5159
+ const fields = this.mapFieldsForObjectConstruct(fieldList);
5160
+ return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT(${fields}) END) WITHIN GROUP (ORDER BY 1 ASC NULLS LAST))[0]`;
5161
+ }
5162
+ sqlAnyValueLastTurtle(name, groupSet, sqlName) {
5163
+ return `(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN ${name} END) WITHIN GROUP (ORDER BY ${name} ASC NULLS LAST))[0] AS ${sqlName}`;
5164
+ }
5165
+ sqlCoaleseMeasuresInline(groupSet, fieldList) {
5166
+ const fields = this.mapFieldsForObjectConstruct(fieldList);
5167
+ const nullValues = fieldList.map((f4) => `'${f4.sqlOutputName}', NULL`).join(", ");
5168
+ return `COALESCE(ARRAY_AGG(CASE WHEN group_set=${groupSet} THEN OBJECT_CONSTRUCT(${fields}) END)[0], OBJECT_CONSTRUCT_KEEP_NULL(${nullValues}))`;
5169
+ }
5170
+ sqlUnnestAlias(source3, alias, _fieldList, _needDistinctKey, isArray2, _isInNestedPipeline) {
5171
+ if (isArray2) {
5172
+ throw new Error("not implemented yet");
5173
+ } else {
5174
+ return `LEFT JOIN LATERAL FLATTEN(INPUT => ifnull(${source3},[1])) AS ${alias}`;
5175
+ }
5176
+ }
5177
+ /*
5178
+ // For comparison against the equivalent function implemented in standardsql dialect
5179
+ select
5180
+ (
5181
+ to_number (
5182
+ substr (md5_hex ('hello'), 1, 15),
5183
+ repeat ('X', 15)
5184
+ ) * 4294967296 + to_number (
5185
+ substr (md5_hex ('hello'), 16, 8),
5186
+ repeat ('X', 8)
5187
+ )
5188
+ ) * 0.000000001 as hash;
5189
+ +-------------------------------+
5190
+ | HASH |
5191
+ |-------------------------------|
5192
+ | 1803811819465386377.040304601 |
5193
+ +-------------------------------+
5194
+ */
5195
+ sqlSumDistinctHashedKey(sqlDistinctKey) {
5196
+ sqlDistinctKey = `${sqlDistinctKey}::STRING`;
5197
+ const upperPart = `to_number(substr(md5_hex(${sqlDistinctKey}), 1, 15), repeat('X', 15)) * 4294967296`;
5198
+ const lowerPart = `to_number(substr(md5_hex(${sqlDistinctKey}), 16, 8), repeat('X', 8))`;
5199
+ const precisionShiftMultiplier = "0.000000001";
5200
+ return `(${upperPart} + ${lowerPart}) * ${precisionShiftMultiplier}`;
5201
+ }
5202
+ sqlGenerateUUID() {
5203
+ return "UUID_STRING()";
5204
+ }
5205
+ sqlFieldReference(alias, fieldName, fieldType, isNested, _isArray) {
5206
+ if (fieldName === "__row_id") {
5207
+ return `${alias}.INDEX::varchar`;
5208
+ } else if (!isNested) {
5209
+ return `${alias}."${fieldName}"`;
5210
+ } else {
5211
+ let snowflakeType = fieldType;
5212
+ if (fieldType === "string") {
5213
+ snowflakeType = "varchar";
5214
+ }
5215
+ return `${alias}.value:"${fieldName}"::${snowflakeType}`;
5216
+ }
5217
+ }
5218
+ sqlUnnestPipelineHead(isSingleton, sourceSQLExpression) {
5219
+ let p3 = sourceSQLExpression;
5220
+ if (isSingleton) {
5221
+ p3 = `[${p3}]`;
5222
+ }
5223
+ return `TABLE(FLATTEN(input =>${p3}))`;
5224
+ }
5225
+ sqlCreateFunction(_id, _funcText) {
5226
+ throw new Error("not implemented yet");
5227
+ }
5228
+ sqlCreateFunctionCombineLastStage(_lastStageName) {
5229
+ throw new Error("not implemented yet");
5230
+ }
5231
+ sqlSelectAliasAsStruct(alias) {
5232
+ return `OBJECT_CONSTRUCT(${alias}.*)`;
5233
+ }
5234
+ sqlMaybeQuoteIdentifier(identifier) {
5235
+ return `"${identifier}"`;
5236
+ }
5237
+ sqlCreateTableAsSelect(tableName, sql) {
5238
+ return `
5239
+ CREATE TEMP TABLE IF NOT EXISTS \`${tableName}\`
5240
+ AS (
5241
+ ${(0, utils_1.indent)(sql)}
5242
+ );
5243
+ `;
5244
+ }
5245
+ sqlTrunc(qi, sqlTime, units) {
5246
+ const tz = (0, dialect_1.qtz)(qi);
5247
+ let truncThis = sqlTime.value;
5248
+ if (tz && sqlTime.valueType === "timestamp") {
5249
+ truncThis = (0, malloy_types_1.mkExpr)`CONVERT_TIMEZONE('${tz}', ${truncThis})`;
5250
+ }
5251
+ return (0, malloy_types_1.mkExpr)`DATE_TRUNC('${units}', ${truncThis})`;
5252
+ }
5253
+ sqlExtract(qi, from, units) {
5254
+ const extractUnits = extractionMap[units] || units;
5255
+ let extractFrom = from.value;
5256
+ const tz = (0, dialect_1.qtz)(qi);
5257
+ if (tz && from.valueType === "timestamp") {
5258
+ extractFrom = (0, malloy_types_1.mkExpr)`CONVERT_TIMEZONE('${tz}', ${extractFrom})`;
5259
+ }
5260
+ const extracted = (0, malloy_types_1.mkExpr)`EXTRACT(${extractUnits} FROM ${extractFrom})`;
5261
+ return extracted;
5262
+ }
5263
+ sqlAlterTime(op, expr2, n7, timeframe) {
5264
+ const interval3 = (0, malloy_types_1.mkExpr)`INTERVAL '${n7} ${timeframe}'`;
5265
+ return (0, malloy_types_1.mkExpr)`((${expr2.value})${op}${interval3})`;
5266
+ }
5267
+ atTz(expr2, tz) {
5268
+ if (tz !== void 0) {
5269
+ return (0, malloy_types_1.mkExpr)`(
5270
+ TO_CHAR(${expr2}::TIMESTAMP_NTZ, 'YYYY-MM-DD HH24:MI:SS.FF9') ||
5271
+ TO_CHAR(CONVERT_TIMEZONE('${tz}', '1970-01-01 00:00:00'), 'TZHTZM')
5272
+ )::TIMESTAMP_TZ`;
5273
+ }
5274
+ return (0, malloy_types_1.mkExpr)`${expr2}::TIMESTAMP_NTZ`;
5275
+ }
5276
+ sqlNow() {
5277
+ return (0, malloy_types_1.mkExpr)`CURRENT_TIMESTAMP()`;
5278
+ }
5279
+ sqlCast(qi, cast) {
5280
+ if (cast.srcType === cast.dstType) {
5281
+ return cast.expr;
5282
+ }
5283
+ if (cast.safe) {
5284
+ throw new Error("Snowflake dialect doesn't support safe cast for a few types");
5285
+ }
5286
+ const tz = (0, dialect_1.qtz)(qi);
5287
+ if (cast.dstType === "date" && cast.srcType === "timestamp") {
5288
+ let castExpr = cast.expr;
5289
+ if (tz) {
5290
+ castExpr = (0, malloy_types_1.mkExpr)`CONVERT_TIMEZONE('${tz}', ${castExpr})`;
5291
+ }
5292
+ return (0, malloy_types_1.mkExpr)`TO_DATE(${castExpr})`;
5293
+ } else if (cast.dstType === "timestamp" && cast.srcType === "date") {
5294
+ const retExpr = (0, malloy_types_1.mkExpr)`TO_TIMESTAMP(${cast.expr})`;
5295
+ return this.atTz(retExpr, tz);
5296
+ }
5297
+ const dstType = typeof cast.dstType === "string" ? this.malloyTypeToSQLType({ type: cast.dstType }) : cast.dstType.raw;
5298
+ return (0, malloy_types_1.mkExpr)`CAST(${cast.expr} AS ${dstType})`;
5299
+ }
5300
+ sqlLiteralTime(qi, timeString, type3, timezone) {
5301
+ const tz = (0, dialect_1.qtz)(qi);
5302
+ let ret = `'${timeString}'::TIMESTAMP_NTZ`;
5303
+ const targetTimeZone = timezone !== null && timezone !== void 0 ? timezone : tz;
5304
+ if (targetTimeZone) {
5305
+ const targetTimeZoneSuffix = `TO_CHAR(CONVERT_TIMEZONE('${targetTimeZone}', '1970-01-01 00:00:00'), 'TZHTZM')`;
5306
+ const retTimeString = `TO_CHAR(${ret}, 'YYYY-MM-DD HH24:MI:SS.FF9')`;
5307
+ ret = `${retTimeString} || ${targetTimeZoneSuffix}`;
5308
+ ret = `(${ret})::TIMESTAMP_TZ`;
5309
+ }
5310
+ switch (type3) {
5311
+ case "date":
5312
+ return `TO_DATE(${ret})`;
5313
+ case "timestamp": {
5314
+ return ret;
5315
+ }
5316
+ }
5317
+ }
5318
+ sqlMeasureTime(from, to, units) {
5319
+ let extractUnits = "nanoseconds";
5320
+ if (from.valueType === "date" || to.valueType === "date") {
5321
+ extractUnits = "seconds";
5322
+ }
5323
+ return (0, malloy_types_1.mkExpr)`TIMESTAMPDIFF(
5324
+ '${units}',
5325
+ '1970-01-01 00:00:00'::TIMESTAMP_NTZ,
5326
+ TIMESTAMPADD(
5327
+ '${extractUnits}',
5328
+ EXTRACT('epoch_${extractUnits}', ${to.value}) - EXTRACT('epoch_${extractUnits}', ${from.value}),
5329
+ '1970-01-01 00:00:00'::TIMESTAMP_NTZ
5330
+ )
5331
+ )`;
5332
+ }
5333
+ sqlRegexpMatch(expr2, regexp) {
5334
+ return (0, malloy_types_1.mkExpr)`(REGEXP_INSTR(${expr2}, ${regexp}) != 0)`;
5335
+ }
5336
+ sqlSampleTable(tableSQL, sample) {
5337
+ if (sample !== void 0) {
5338
+ if ((0, malloy_types_1.isSamplingEnable)(sample) && sample.enable) {
5339
+ sample = this.defaultSampling;
5340
+ }
5341
+ if ((0, malloy_types_1.isSamplingRows)(sample)) {
5342
+ return `(SELECT * FROM ${tableSQL} TABLESAMPLE (${sample.rows} ROWS))`;
5343
+ } else if ((0, malloy_types_1.isSamplingPercent)(sample)) {
5344
+ return `(SELECT * FROM ${tableSQL} TABLESAMPLE (${sample.percent}))`;
5345
+ }
5346
+ }
5347
+ return tableSQL;
5348
+ }
5349
+ sqlOrderBy(orderTerms) {
5350
+ return `ORDER BY ${orderTerms.map((t9) => `${t9} NULLS LAST`).join(",")}`;
5351
+ }
5352
+ sqlLiteralString(literal) {
5353
+ const noVirgule = literal.replace(/\\/g, "\\\\");
5354
+ return "'" + noVirgule.replace(/'/g, "\\'") + "'";
5355
+ }
5356
+ sqlLiteralRegexp(literal) {
5357
+ const noVirgule = literal.replace(/\\/g, "\\\\");
5358
+ return "'" + noVirgule.replace(/'/g, "\\'") + "'";
5359
+ }
5360
+ getGlobalFunctionDef(name) {
5361
+ return functions_1.SNOWFLAKE_FUNCTIONS.get(name);
5362
+ }
5363
+ malloyTypeToSQLType(malloyType) {
5364
+ if (malloyType.type === "number") {
5365
+ if (malloyType.numberType === "integer") {
5366
+ return "integer";
5367
+ } else {
5368
+ return "double";
5369
+ }
5370
+ }
5371
+ return malloyType.type;
5372
+ }
5373
+ sqlTypeToMalloyType(sqlType) {
5374
+ var _a, _b;
5375
+ const baseSqlType = (_b = (_a = sqlType.match(/^([\w\s]+)/)) === null || _a === void 0 ? void 0 : _a.at(0)) !== null && _b !== void 0 ? _b : sqlType;
5376
+ return snowflakeToMalloyTypes[baseSqlType.trim().toLowerCase()];
5377
+ }
5378
+ castToString(expression3) {
5379
+ return `TO_VARCHAR(${expression3})`;
5380
+ }
5381
+ concat(...values4) {
5382
+ return values4.join(" || ");
5383
+ }
5384
+ validateTypeName(sqlType) {
5385
+ return sqlType.match(/^[A-Za-z\s(),[\]0-9]*$/) !== null;
5386
+ }
5387
+ };
5388
+ exports.SnowflakeDialect = SnowflakeDialect;
5389
+ }
5390
+ });
5391
+
5392
+ // ../malloy/dist/dialect/snowflake/index.js
5393
+ var require_snowflake2 = __commonJS({
5394
+ "../malloy/dist/dialect/snowflake/index.js"(exports) {
5395
+ "use strict";
5396
+ var __createBinding = exports && exports.__createBinding || (Object.create ? function(o5, m4, k2, k22) {
5397
+ if (k22 === void 0)
5398
+ k22 = k2;
5399
+ var desc = Object.getOwnPropertyDescriptor(m4, k2);
5400
+ if (!desc || ("get" in desc ? !m4.__esModule : desc.writable || desc.configurable)) {
5401
+ desc = { enumerable: true, get: function() {
5402
+ return m4[k2];
5403
+ } };
5404
+ }
5405
+ Object.defineProperty(o5, k22, desc);
5406
+ } : function(o5, m4, k2, k22) {
5407
+ if (k22 === void 0)
5408
+ k22 = k2;
5409
+ o5[k22] = m4[k2];
5410
+ });
5411
+ var __exportStar = exports && exports.__exportStar || function(m4, exports2) {
5412
+ for (var p3 in m4)
5413
+ if (p3 !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p3))
5414
+ __createBinding(exports2, m4, p3);
5415
+ };
5416
+ Object.defineProperty(exports, "__esModule", { value: true });
5417
+ __exportStar(require_snowflake(), exports);
5418
+ }
5419
+ });
5420
+
4736
5421
  // ../malloy/dist/dialect/dialect_map.js
4737
5422
  var require_dialect_map = __commonJS({
4738
5423
  "../malloy/dist/dialect/dialect_map.js"(exports) {
@@ -4741,6 +5426,7 @@ ${hackSplitComment}
4741
5426
  exports.getDialectFunction = exports.registerDialect = exports.getDialect = void 0;
4742
5427
  var duckdb_1 = require_duckdb2();
4743
5428
  var postgres_1 = require_postgres2();
5429
+ var snowflake_1 = require_snowflake2();
4744
5430
  var standardsql_1 = require_standardsql2();
4745
5431
  var dialectMap = /* @__PURE__ */ new Map();
4746
5432
  function getDialect(name) {
@@ -4758,6 +5444,7 @@ ${hackSplitComment}
4758
5444
  registerDialect(new postgres_1.PostgresDialect());
4759
5445
  registerDialect(new standardsql_1.StandardSQLDialect());
4760
5446
  registerDialect(new duckdb_1.DuckDBDialect());
5447
+ registerDialect(new snowflake_1.SnowflakeDialect());
4761
5448
  function paramsEqual(a5, b4) {
4762
5449
  return a5.params.length === b4.params.length && a5.params.every((param2, i6) => {
4763
5450
  const otherParam = b4.params[i6];
@@ -4832,7 +5519,7 @@ ${hackSplitComment}
4832
5519
  "../malloy/dist/dialect/index.js"(exports) {
4833
5520
  "use strict";
4834
5521
  Object.defineProperty(exports, "__esModule", { value: true });
4835
- exports.FUNCTIONS = exports.getDialectFunction = exports.registerDialect = exports.getDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.qtz = exports.Dialect = exports.sql = exports.literal = exports.params = exports.param = exports.sqlFragment = exports.spread = exports.maxScalar = exports.minAggregate = exports.minScalar = exports.overload = exports.makeParam = exports.anyExprType = exports.arg = void 0;
5522
+ exports.FUNCTIONS = exports.getDialectFunction = exports.registerDialect = exports.getDialect = exports.SnowflakeDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.qtz = exports.Dialect = exports.sql = exports.literal = exports.params = exports.param = exports.sqlFragment = exports.spread = exports.maxScalar = exports.minAggregate = exports.minScalar = exports.overload = exports.makeParam = exports.anyExprType = exports.arg = void 0;
4836
5523
  var util_1 = require_util();
4837
5524
  Object.defineProperty(exports, "arg", { enumerable: true, get: function() {
4838
5525
  return util_1.arg;
@@ -4892,6 +5579,10 @@ ${hackSplitComment}
4892
5579
  Object.defineProperty(exports, "DuckDBDialect", { enumerable: true, get: function() {
4893
5580
  return duckdb_1.DuckDBDialect;
4894
5581
  } });
5582
+ var snowflake_1 = require_snowflake2();
5583
+ Object.defineProperty(exports, "SnowflakeDialect", { enumerable: true, get: function() {
5584
+ return snowflake_1.SnowflakeDialect;
5585
+ } });
4895
5586
  var dialect_map_1 = require_dialect_map();
4896
5587
  Object.defineProperty(exports, "getDialect", { enumerable: true, get: function() {
4897
5588
  return dialect_map_1.getDialect;
@@ -5353,13 +6044,13 @@ ${(0, utils_1.indent)(sql)})
5353
6044
  throw new Error(`Join ${joinName} not found in result set`);
5354
6045
  }
5355
6046
  if (!join3.leafiest || join3.makeUniqueKey) {
5356
- func = "COUNT(DISTINCT";
6047
+ func = "COUNT(DISTINCT ";
5357
6048
  thing = struct.getDistinctKey().generateExpression(resultSet);
5358
6049
  }
5359
6050
  if (state.whereSQL) {
5360
- return `${func} CASE WHEN ${state.whereSQL} THEN ${thing} END)`;
6051
+ return `${func}CASE WHEN ${state.whereSQL} THEN ${thing} END)`;
5361
6052
  } else {
5362
- return `${func} ${thing})`;
6053
+ return `${func}${thing})`;
5363
6054
  }
5364
6055
  }
5365
6056
  generateDialect(resultSet, context3, expr2, state) {
@@ -5658,7 +6349,7 @@ ${(0, utils_1.indent)(sql)})
5658
6349
  SUM(DISTINCT ${uniqueInt})
5659
6350
  )`;
5660
6351
  let ret = `(${sumSQL}/(${multiplier}*1.0))`;
5661
- ret = `CAST(${ret} as ${dialect.defaultNumberType})`;
6352
+ ret = `CAST(${ret} AS ${dialect.defaultNumberType})`;
5662
6353
  return ret;
5663
6354
  }
5664
6355
  var FieldInstanceField = class {
@@ -6085,6 +6776,7 @@ ${(0, utils_1.indent)(sql)})
6085
6776
  dialectFieldList.push({
6086
6777
  type: f4.type,
6087
6778
  sqlExpression: (0, malloy_types_1.getIdentifier)(f4),
6779
+ rawName: (0, malloy_types_1.getIdentifier)(f4),
6088
6780
  sqlOutputName: (0, malloy_types_1.getIdentifier)(f4)
6089
6781
  });
6090
6782
  }
@@ -6546,7 +7238,7 @@ ${(0, utils_1.indent)(sql)})
6546
7238
  const matrixOperation = structRelationship.matrixOperation.toUpperCase();
6547
7239
  if (ji.makeUniqueKey) {
6548
7240
  const passKeys = this.generateSQLPassthroughKeys(qs);
6549
- structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, x.* ${passKeys} FROM ${structSQL} as x)`;
7241
+ structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as ${qs.dialect.sqlMaybeQuoteIdentifier("__distinct_key")}, x.* ${passKeys} FROM ${structSQL} as x)`;
6550
7242
  }
6551
7243
  let onCondition = "";
6552
7244
  if (qs.parent === void 0) {
@@ -6643,7 +7335,7 @@ ${(0, utils_1.indent)(select2)}) AS ${ji.alias}
6643
7335
  if (structRelationship.type === "basetable") {
6644
7336
  if (ji.makeUniqueKey) {
6645
7337
  const passKeys = this.generateSQLPassthroughKeys(qs);
6646
- structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as __distinct_key, x.* ${passKeys} FROM ${structSQL} as x)`;
7338
+ structSQL = `(SELECT ${qs.dialect.sqlGenerateUUID()} as ${qs.dialect.sqlMaybeQuoteIdentifier("__distinct_key")}, x.* ${passKeys} FROM ${structSQL} as x)`;
6647
7339
  }
6648
7340
  s8 += `FROM ${structSQL} as ${ji.alias}
6649
7341
  `;
@@ -7014,12 +7706,14 @@ FROM ${stage0Name}
7014
7706
  dialectFieldList.push({
7015
7707
  type: field3 instanceof FieldInstanceField ? field3.f.fieldDef.type : "struct",
7016
7708
  sqlExpression: this.parent.dialect.sqlMaybeQuoteIdentifier(`${name}__${resultStruct.groupSet}`),
7709
+ rawName: name,
7017
7710
  sqlOutputName: sqlName
7018
7711
  });
7019
7712
  } else if (resultStruct.firstSegment.type === "project" && field3 instanceof FieldInstanceField && field3.fieldUsage.type === "result") {
7020
7713
  dialectFieldList.push({
7021
7714
  type: field3.type,
7022
7715
  sqlExpression: field3.f.generateExpression(resultStruct),
7716
+ rawName: name,
7023
7717
  sqlOutputName: sqlName
7024
7718
  });
7025
7719
  }
@@ -7185,6 +7879,7 @@ FROM ${stage0Name}
7185
7879
  const fieldValueColumn = dialect.sqlMaybeQuoteIdentifier("fieldValue");
7186
7880
  const fieldTypeColumn = dialect.sqlMaybeQuoteIdentifier("fieldType");
7187
7881
  const fieldRangeColumn = dialect.sqlMaybeQuoteIdentifier("fieldRange");
7882
+ const weightColumn = dialect.sqlMaybeQuoteIdentifier("weight");
7188
7883
  const measureName2 = this.firstSegment.weightMeasure;
7189
7884
  if (measureName2) {
7190
7885
  measureSQL = this.rootResult.getField(measureName2).f.generateExpression(this.rootResult);
@@ -7230,7 +7925,7 @@ FROM ${stage0Name}
7230
7925
  }
7231
7926
  s8 += ` END as ${fieldValueColumn},
7232
7927
  `;
7233
- s8 += ` ${measureSQL} as weight,
7928
+ s8 += ` ${measureSQL} as ${weightColumn},
7234
7929
  `;
7235
7930
  s8 += " CASE group_set\n WHEN 99999 THEN ''";
7236
7931
  for (let i6 = 0; i6 < fields.length; i6++) {
@@ -7259,7 +7954,7 @@ FROM ${stage0Name}
7259
7954
  ${fieldPathColumn},
7260
7955
  ${fieldTypeColumn},
7261
7956
  COALESCE(${fieldValueColumn}, ${fieldRangeColumn}) as ${fieldValueColumn},
7262
- weight
7957
+ ${weightColumn}
7263
7958
  FROM ${resultStage}
7264
7959
  `);
7265
7960
  return this.resultStage;
@@ -7843,6 +8538,7 @@ FROM ${resultStage}
7843
8538
  const fieldPathColumn = struct.dialect.sqlMaybeQuoteIdentifier("fieldPath");
7844
8539
  const fieldValueColumn = struct.dialect.sqlMaybeQuoteIdentifier("fieldValue");
7845
8540
  const fieldTypeColumn = struct.dialect.sqlMaybeQuoteIdentifier("fieldType");
8541
+ const weightColumn = struct.dialect.sqlMaybeQuoteIdentifier("weight");
7846
8542
  let sqlPDT = this.exploreSearchSQLMap.get(explore);
7847
8543
  if (sqlPDT === void 0) {
7848
8544
  sqlPDT = this.compileQuery(indexQuery, false).sql;
@@ -7853,11 +8549,11 @@ FROM ${resultStage}
7853
8549
  ${fieldPathColumn},
7854
8550
  ${fieldValueColumn},
7855
8551
  ${fieldTypeColumn},
7856
- weight,
8552
+ ${weightColumn},
7857
8553
  CASE WHEN lower(${fieldValueColumn}) LIKE lower(${generateSQLStringLiteral(searchValue + "%")}) THEN 1 ELSE 0 END as match_first
7858
8554
  FROM ${await connection.manifestTemporaryTable(sqlPDT)}
7859
8555
  WHERE lower(${fieldValueColumn}) LIKE lower(${generateSQLStringLiteral("%" + searchValue + "%")}) ${searchField !== void 0 ? ` AND ${fieldNameColumn} = '` + searchField + "' \n" : ""}
7860
- ORDER BY CASE WHEN lower(${fieldValueColumn}) LIKE lower(${generateSQLStringLiteral(searchValue + "%")}) THEN 1 ELSE 0 END DESC, weight DESC
8556
+ ORDER BY CASE WHEN lower(${fieldValueColumn}) LIKE lower(${generateSQLStringLiteral(searchValue + "%")}) THEN 1 ELSE 0 END DESC, ${weightColumn} DESC
7861
8557
  LIMIT ${limit}
7862
8558
  `;
7863
8559
  if (struct.dialect.hasFinalStage) {
@@ -7869,7 +8565,7 @@ ${struct.dialect.sqlFinalStage("__stage0", [
7869
8565
  fieldPathColumn,
7870
8566
  fieldValueColumn,
7871
8567
  fieldTypeColumn,
7872
- "weight",
8568
+ weightColumn,
7873
8569
  "match_first"
7874
8570
  ])}`;
7875
8571
  }
@@ -10830,7 +11526,7 @@ ${struct.dialect.sqlFinalStage("__stage0", [
10830
11526
  });
10831
11527
 
10832
11528
  // ../../node_modules/is-nan/index.js
10833
- var require_is_nan4 = __commonJS({
11529
+ var require_is_nan5 = __commonJS({
10834
11530
  "../../node_modules/is-nan/index.js"(exports, module) {
10835
11531
  "use strict";
10836
11532
  var callBind = require_call_bind();
@@ -10918,7 +11614,7 @@ ${struct.dialect.sqlFinalStage("__stage0", [
10918
11614
  var objectGetOwnPropertySymbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols : function() {
10919
11615
  return [];
10920
11616
  };
10921
- var numberIsNaN = Number.isNaN ? Number.isNaN : require_is_nan4();
11617
+ var numberIsNaN = Number.isNaN ? Number.isNaN : require_is_nan5();
10922
11618
  function uncurryThis(f4) {
10923
11619
  return f4.call.bind(f4);
10924
11620
  }
@@ -70601,6 +71297,13 @@ ${errText}`, errors);
70601
71297
  get supportsNesting() {
70602
71298
  return (0, dialect_1.getDialect)(this.connection.dialectName).supportsNesting;
70603
71299
  }
71300
+ // quote a column name
71301
+ quote(column) {
71302
+ return (0, dialect_1.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(column);
71303
+ }
71304
+ getQuoter() {
71305
+ return (x6) => this.quote(x6.toString());
71306
+ }
70604
71307
  };
70605
71308
  exports.SingleConnectionRuntime = SingleConnectionRuntime;
70606
71309
  var FluentState = class {
@@ -71824,8 +72527,8 @@ ${errText}`, errors);
71824
72527
  "../malloy/dist/index.js"(exports) {
71825
72528
  "use strict";
71826
72529
  Object.defineProperty(exports, "__esModule", { value: true });
71827
- exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.indent = exports.expressionIsCalculation = exports.mkExpr = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.Segment = exports.FUNCTIONS = exports.Dialect = exports.spread = exports.literal = exports.params = exports.param = exports.sqlFragment = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
71828
- exports.Tag = exports.toAsyncGenerator = void 0;
72530
+ exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.MalloyTranslator = exports.HighlightType = exports.indent = exports.expressionIsCalculation = exports.mkExpr = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.Segment = exports.FUNCTIONS = exports.Dialect = exports.spread = exports.literal = exports.params = exports.param = exports.sqlFragment = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
72531
+ exports.Tag = exports.toAsyncGenerator = exports.Explore = void 0;
71829
72532
  var dialect_1 = require_dialect2();
71830
72533
  Object.defineProperty(exports, "DuckDBDialect", { enumerable: true, get: function() {
71831
72534
  return dialect_1.DuckDBDialect;
@@ -71836,6 +72539,9 @@ ${errText}`, errors);
71836
72539
  Object.defineProperty(exports, "PostgresDialect", { enumerable: true, get: function() {
71837
72540
  return dialect_1.PostgresDialect;
71838
72541
  } });
72542
+ Object.defineProperty(exports, "SnowflakeDialect", { enumerable: true, get: function() {
72543
+ return dialect_1.SnowflakeDialect;
72544
+ } });
71839
72545
  Object.defineProperty(exports, "registerDialect", { enumerable: true, get: function() {
71840
72546
  return dialect_1.registerDialect;
71841
72547
  } });