@malloydata/malloy 0.0.335 → 0.0.336
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/CONTEXT.md +4 -3
- package/MALLOY_API.md +129 -0
- package/dist/annotation.d.ts +0 -2
- package/dist/annotation.js +29 -23
- package/dist/api/asynchronous.d.ts +1 -1
- package/dist/api/foundation/cache.d.ts +32 -0
- package/dist/api/foundation/cache.js +92 -0
- package/dist/api/foundation/compile.d.ts +175 -0
- package/dist/api/foundation/compile.js +391 -0
- package/dist/api/foundation/core.d.ts +493 -0
- package/dist/api/foundation/core.js +1247 -0
- package/dist/api/foundation/document.d.ts +167 -0
- package/dist/api/foundation/document.js +206 -0
- package/dist/api/foundation/index.d.ts +10 -0
- package/dist/api/foundation/index.js +77 -0
- package/dist/api/foundation/readers.d.ts +53 -0
- package/dist/api/foundation/readers.js +134 -0
- package/dist/api/foundation/result.d.ts +185 -0
- package/dist/api/foundation/result.js +704 -0
- package/dist/api/foundation/runtime.d.ts +361 -0
- package/dist/api/foundation/runtime.js +733 -0
- package/dist/api/foundation/types.d.ts +54 -0
- package/dist/api/foundation/types.js +7 -0
- package/dist/api/foundation/writers.d.ts +42 -0
- package/dist/api/foundation/writers.js +230 -0
- package/dist/api/util.d.ts +1 -1
- package/dist/connection/base_connection.d.ts +5 -0
- package/dist/connection/types.d.ts +5 -0
- package/dist/dialect/duckdb/duckdb.js +2 -1
- package/dist/dialect/snowflake/snowflake.js +7 -1
- package/dist/dialect/trino/trino.js +7 -2
- package/dist/index.d.ts +6 -3
- package/dist/index.js +30 -26
- package/dist/lang/ast/error-factory.js +3 -5
- package/dist/lang/ast/source-elements/query-source.js +2 -7
- package/dist/lang/ast/source-elements/refined-source.js +11 -1
- package/dist/lang/ast/source-elements/sql-source.d.ts +1 -1
- package/dist/lang/ast/source-elements/sql-source.js +18 -3
- package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
- package/dist/lang/ast/sql-elements/sql-string.js +18 -1
- package/dist/lang/ast/statements/define-source.js +7 -2
- package/dist/lang/ast/statements/import-statement.js +53 -21
- package/dist/lang/ast/types/document-compile-result.d.ts +1 -0
- package/dist/lang/ast/types/malloy-element.d.ts +3 -1
- package/dist/lang/ast/types/malloy-element.js +23 -7
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/malloy-to-ast.js +1 -1
- package/dist/lang/parse-malloy.d.ts +3 -2
- package/dist/lang/parse-malloy.js +14 -25
- package/dist/lang/test/test-translator.js +1 -0
- package/dist/lang/translate-response.d.ts +1 -0
- package/dist/model/constant_expression_compiler.js +6 -7
- package/dist/model/index.d.ts +3 -1
- package/dist/model/index.js +15 -9
- package/dist/model/malloy_types.d.ts +89 -15
- package/dist/model/malloy_types.js +12 -0
- package/dist/model/persist_utils.d.ts +47 -0
- package/dist/model/persist_utils.js +257 -0
- package/dist/model/query_model_impl.d.ts +2 -4
- package/dist/model/query_model_impl.js +5 -13
- package/dist/model/query_node.d.ts +1 -2
- package/dist/model/query_node.js +3 -13
- package/dist/model/query_query.d.ts +17 -1
- package/dist/model/query_query.js +81 -36
- package/dist/model/source_def_utils.d.ts +50 -0
- package/dist/model/source_def_utils.js +154 -0
- package/dist/model/sql_block.d.ts +5 -1
- package/dist/model/sql_block.js +29 -4
- package/dist/model/sql_compiled.d.ts +29 -0
- package/dist/model/sql_compiled.js +102 -0
- package/dist/model/stage_writer.d.ts +1 -3
- package/dist/model/stage_writer.js +7 -25
- package/dist/model/utils.d.ts +20 -1
- package/dist/model/utils.js +40 -0
- package/dist/run_sql_options.d.ts +0 -1
- package/dist/taggable.d.ts +10 -0
- package/dist/taggable.js +7 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -4
- package/dist/malloy.d.ts +0 -1365
- package/dist/malloy.js +0 -3421
- package/dist/model/materialization/utils.d.ts +0 -3
- package/dist/model/materialization/utils.js +0 -41
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.StageWriter = void 0;
|
|
8
|
-
const utils_1 = require("./
|
|
9
|
-
const utils_2 = require("./utils");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
10
9
|
class StageWriter {
|
|
11
10
|
constructor(useCTE = true, parent) {
|
|
12
11
|
this.parent = parent;
|
|
@@ -14,7 +13,6 @@ class StageWriter {
|
|
|
14
13
|
this.stageNames = [];
|
|
15
14
|
this.udfs = [];
|
|
16
15
|
this.pdts = [];
|
|
17
|
-
this.dependenciesToMaterialize = {};
|
|
18
16
|
this.stagePrefix = '__stage';
|
|
19
17
|
this.stageNumber = 0;
|
|
20
18
|
this.useCTE = useCTE;
|
|
@@ -43,7 +41,7 @@ class StageWriter {
|
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
43
|
this.withs[0] = sql;
|
|
46
|
-
return (0,
|
|
44
|
+
return (0, utils_1.indent)(`\n(${sql})\n`);
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
addUDF(stageWriter, dialect, structDef) {
|
|
@@ -53,31 +51,15 @@ class StageWriter {
|
|
|
53
51
|
if (lastStageName === undefined) {
|
|
54
52
|
throw new Error('Internal Error: no stage to combine');
|
|
55
53
|
}
|
|
56
|
-
sql += dialect.sqlCreateFunctionCombineLastStage(lastStageName, (0,
|
|
54
|
+
sql += dialect.sqlCreateFunctionCombineLastStage(lastStageName, (0, utils_1.getDialectFieldList)(structDef), (_a = structDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.orderBy);
|
|
57
55
|
const id = `${dialect.udfPrefix}${this.root().udfs.length}`;
|
|
58
56
|
sql = dialect.sqlCreateFunction(id, sql);
|
|
59
57
|
this.root().udfs.push(sql);
|
|
60
58
|
return id;
|
|
61
59
|
}
|
|
62
|
-
addMaterializedQuery(fieldName, query, materializatedTablePrefix) {
|
|
63
|
-
var _a;
|
|
64
|
-
const name = query.name;
|
|
65
|
-
if (!name) {
|
|
66
|
-
throw new Error(`Source ${fieldName} on a unnamed query that is tagged as materialize, only named queries can be materialized.`);
|
|
67
|
-
}
|
|
68
|
-
const path = (_a = query.location) === null || _a === void 0 ? void 0 : _a.url;
|
|
69
|
-
if (!path) {
|
|
70
|
-
throw new Error(`Trying to materialize query ${name}, but its path is not set.`);
|
|
71
|
-
}
|
|
72
|
-
// Creating an object that should uniquely identify a query within a Malloy model repo.
|
|
73
|
-
const queryMaterializationSpec = (0, utils_1.buildQueryMaterializationSpec)(path, name, materializatedTablePrefix);
|
|
74
|
-
this.root().dependenciesToMaterialize[queryMaterializationSpec.id] =
|
|
75
|
-
queryMaterializationSpec;
|
|
76
|
-
return queryMaterializationSpec.id;
|
|
77
|
-
}
|
|
78
60
|
addPDT(baseName, dialect) {
|
|
79
61
|
const sql = this.combineStages(false).sql + this.withs[this.withs.length - 1];
|
|
80
|
-
const name = baseName + (0,
|
|
62
|
+
const name = baseName + (0, utils_1.generateHash)(sql);
|
|
81
63
|
const tableName = `scratch.${name}`;
|
|
82
64
|
this.root().pdts.push(dialect.sqlCreateTableAsSelect(tableName, sql));
|
|
83
65
|
return tableName;
|
|
@@ -97,7 +79,7 @@ class StageWriter {
|
|
|
97
79
|
if (sql === undefined) {
|
|
98
80
|
throw new Error(`Expected sql WITH to be present for stage ${lastStageName}.`);
|
|
99
81
|
}
|
|
100
|
-
w += `${prefix}${lastStageName} AS (\n${(0,
|
|
82
|
+
w += `${prefix}${lastStageName} AS (\n${(0, utils_1.indent)(sql)})\n`;
|
|
101
83
|
prefix = ', ';
|
|
102
84
|
}
|
|
103
85
|
return { sql: w, lastStageName };
|
|
@@ -116,11 +98,11 @@ class StageWriter {
|
|
|
116
98
|
generateCoorelatedSubQuery(dialect, structDef) {
|
|
117
99
|
var _a, _b;
|
|
118
100
|
if (!this.useCTE) {
|
|
119
|
-
return dialect.sqlCreateFunctionCombineLastStage(`(${this.withs[0]})`, (0,
|
|
101
|
+
return dialect.sqlCreateFunctionCombineLastStage(`(${this.withs[0]})`, (0, utils_1.getDialectFieldList)(structDef), (_a = structDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.orderBy);
|
|
120
102
|
}
|
|
121
103
|
else {
|
|
122
104
|
return (this.combineStages(true).sql +
|
|
123
|
-
dialect.sqlCreateFunctionCombineLastStage(this.getName(this.withs.length - 1), (0,
|
|
105
|
+
dialect.sqlCreateFunctionCombineLastStage(this.getName(this.withs.length - 1), (0, utils_1.getDialectFieldList)(structDef), (_b = structDef.resultMetadata) === null || _b === void 0 ? void 0 : _b.orderBy));
|
|
124
106
|
}
|
|
125
107
|
}
|
|
126
108
|
}
|
package/dist/model/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Expr, GenericSQLExpr, StructDef } from './malloy_types';
|
|
1
|
+
import type { Expr, GenericSQLExpr, ModelDef, StructDef } from './malloy_types';
|
|
2
2
|
import type { DialectFieldList } from '../dialect';
|
|
3
3
|
/** simple indent function */
|
|
4
4
|
export declare function indent(s: string): string;
|
|
@@ -22,6 +22,20 @@ export declare class AndChain {
|
|
|
22
22
|
sql(whereOrHaving?: 'where' | 'having'): string;
|
|
23
23
|
}
|
|
24
24
|
export declare function generateHash(input: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Compute a digest for lookup/identity purposes (not cryptographic).
|
|
27
|
+
*
|
|
28
|
+
* Uses blueimp-md5 for these reasons:
|
|
29
|
+
* - Works in both Node.js and browsers (no native crypto dependency)
|
|
30
|
+
* - Synchronous API (unlike Web Crypto which is async)
|
|
31
|
+
* - Well-maintained by Sebastian Tschan (blueimp), a known maintainer
|
|
32
|
+
* - High adoption (~1.7M weekly downloads)
|
|
33
|
+
* - MD5 is fast and produces short hex strings - perfect for cache keys
|
|
34
|
+
*
|
|
35
|
+
* Takes variable string arguments and combines them in a collision-resistant
|
|
36
|
+
* way by including the length of each string (similar to pathToKey pattern).
|
|
37
|
+
*/
|
|
38
|
+
export declare function makeDigest(...parts: string[]): string;
|
|
25
39
|
export declare function joinWith<T>(els: T[][], sep: T): T[];
|
|
26
40
|
export declare function range(start: number, end: number): number[];
|
|
27
41
|
export declare function exprKids(eNode: Expr): IterableIterator<Expr>;
|
|
@@ -49,3 +63,8 @@ export declare class GenerateState {
|
|
|
49
63
|
withApply(s: string): GenerateState;
|
|
50
64
|
withTotal(groupSet: number): GenerateState;
|
|
51
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Create an empty ModelDef with the given name.
|
|
68
|
+
* Use this factory to ensure all required fields are present.
|
|
69
|
+
*/
|
|
70
|
+
export declare function mkModelDef(name: string): ModelDef;
|
package/dist/model/utils.js
CHANGED
|
@@ -21,11 +21,15 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
24
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
28
|
exports.GenerateState = exports.AndChain = void 0;
|
|
26
29
|
exports.indent = indent;
|
|
27
30
|
exports.generateSQLStringLiteral = generateSQLStringLiteral;
|
|
28
31
|
exports.generateHash = generateHash;
|
|
32
|
+
exports.makeDigest = makeDigest;
|
|
29
33
|
exports.joinWith = joinWith;
|
|
30
34
|
exports.range = range;
|
|
31
35
|
exports.exprKids = exprKids;
|
|
@@ -36,7 +40,9 @@ exports.getDialectFieldList = getDialectFieldList;
|
|
|
36
40
|
exports.pathToKey = pathToKey;
|
|
37
41
|
exports.groupingKey = groupingKey;
|
|
38
42
|
exports.caseGroup = caseGroup;
|
|
43
|
+
exports.mkModelDef = mkModelDef;
|
|
39
44
|
const uuid_1 = require("uuid");
|
|
45
|
+
const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
|
|
40
46
|
const malloy_types_1 = require("./malloy_types");
|
|
41
47
|
/** simple indent function */
|
|
42
48
|
function indent(s) {
|
|
@@ -108,6 +114,26 @@ function generateHash(input) {
|
|
|
108
114
|
const MALLOY_UUID = '76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6';
|
|
109
115
|
return (0, uuid_1.v5)(input, MALLOY_UUID);
|
|
110
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Compute a digest for lookup/identity purposes (not cryptographic).
|
|
119
|
+
*
|
|
120
|
+
* Uses blueimp-md5 for these reasons:
|
|
121
|
+
* - Works in both Node.js and browsers (no native crypto dependency)
|
|
122
|
+
* - Synchronous API (unlike Web Crypto which is async)
|
|
123
|
+
* - Well-maintained by Sebastian Tschan (blueimp), a known maintainer
|
|
124
|
+
* - High adoption (~1.7M weekly downloads)
|
|
125
|
+
* - MD5 is fast and produces short hex strings - perfect for cache keys
|
|
126
|
+
*
|
|
127
|
+
* Takes variable string arguments and combines them in a collision-resistant
|
|
128
|
+
* way by including the length of each string (similar to pathToKey pattern).
|
|
129
|
+
*/
|
|
130
|
+
function makeDigest(...parts) {
|
|
131
|
+
// Combine parts with length prefix to avoid collisions
|
|
132
|
+
// e.g., ("ab", "c") vs ("a", "bc") both concat to "abc"
|
|
133
|
+
// but with lengths: "2:ab/1:c" vs "1:a/2:bc"
|
|
134
|
+
const combined = parts.map(p => `${p.length}:${p}`).join('/');
|
|
135
|
+
return (0, blueimp_md5_1.default)(combined);
|
|
136
|
+
}
|
|
111
137
|
function joinWith(els, sep) {
|
|
112
138
|
const result = [];
|
|
113
139
|
for (let i = 0; i < els.length; i++) {
|
|
@@ -260,4 +286,18 @@ class GenerateState {
|
|
|
260
286
|
}
|
|
261
287
|
}
|
|
262
288
|
exports.GenerateState = GenerateState;
|
|
289
|
+
/**
|
|
290
|
+
* Create an empty ModelDef with the given name.
|
|
291
|
+
* Use this factory to ensure all required fields are present.
|
|
292
|
+
*/
|
|
293
|
+
function mkModelDef(name) {
|
|
294
|
+
return {
|
|
295
|
+
name,
|
|
296
|
+
exports: [],
|
|
297
|
+
contents: {},
|
|
298
|
+
sourceRegistry: {},
|
|
299
|
+
queryList: [],
|
|
300
|
+
dependencies: {},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
263
303
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TagParseSpec, MalloyTagParse } from './annotation';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for objects that have Malloy tag annotations.
|
|
4
|
+
* This is part of the runtime API - objects returned from the Malloy
|
|
5
|
+
* runtime implement this interface to expose their tag metadata.
|
|
6
|
+
*/
|
|
7
|
+
export interface Taggable {
|
|
8
|
+
tagParse: (spec?: TagParseSpec) => MalloyTagParse;
|
|
9
|
+
getTaglines: (prefix?: RegExp) => string[];
|
|
10
|
+
}
|
package/dist/taggable.js
ADDED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.336";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.336';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.336",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -45,11 +45,12 @@
|
|
|
45
45
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@malloydata/malloy-filter": "0.0.
|
|
49
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
50
|
-
"@malloydata/malloy-tag": "0.0.
|
|
48
|
+
"@malloydata/malloy-filter": "0.0.336",
|
|
49
|
+
"@malloydata/malloy-interfaces": "0.0.336",
|
|
50
|
+
"@malloydata/malloy-tag": "0.0.336",
|
|
51
51
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
52
52
|
"assert": "^2.0.0",
|
|
53
|
+
"blueimp-md5": "^2.19.0",
|
|
53
54
|
"jaro-winkler": "^0.2.8",
|
|
54
55
|
"jest-diff": "^29.6.2",
|
|
55
56
|
"lodash": "^4.17.20",
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
"uuid": "^8.3.2"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
61
|
+
"@types/blueimp-md5": "^2.18.2",
|
|
60
62
|
"@types/jaro-winkler": "^0.2.3",
|
|
61
63
|
"@types/lodash": "^4.14.165",
|
|
62
64
|
"@types/luxon": "^3.5.0",
|