@malloydata/malloy 0.0.1
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/README.md +39 -0
- package/dist/connection_utils.d.ts +1 -0
- package/dist/connection_utils.js +56 -0
- package/dist/dialect/dialect-map.d.ts +3 -0
- package/dist/dialect/dialect-map.js +33 -0
- package/dist/dialect/dialect.d.ts +64 -0
- package/dist/dialect/dialect.js +64 -0
- package/dist/dialect/dialect_map.d.ts +3 -0
- package/dist/dialect/dialect_map.js +35 -0
- package/dist/dialect/duckdb.d.ts +49 -0
- package/dist/dialect/duckdb.js +349 -0
- package/dist/dialect/index.d.ts +6 -0
- package/dist/dialect/index.js +27 -0
- package/dist/dialect/postgres.d.ts +49 -0
- package/dist/dialect/postgres.js +308 -0
- package/dist/dialect/standardsql.d.ts +46 -0
- package/dist/dialect/standardsql.js +361 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +47 -0
- package/dist/lang/ast/apply-expr.d.ts +16 -0
- package/dist/lang/ast/apply-expr.js +215 -0
- package/dist/lang/ast/ast-expr.d.ts +291 -0
- package/dist/lang/ast/ast-expr.js +1056 -0
- package/dist/lang/ast/ast-main.d.ts +480 -0
- package/dist/lang/ast/ast-main.js +2096 -0
- package/dist/lang/ast/ast-time-expr.d.ts +109 -0
- package/dist/lang/ast/ast-time-expr.js +550 -0
- package/dist/lang/ast/ast-types.d.ts +83 -0
- package/dist/lang/ast/ast-types.js +215 -0
- package/dist/lang/ast/index.d.ts +5 -0
- package/dist/lang/ast/index.js +34 -0
- package/dist/lang/ast/time-utils.d.ts +8 -0
- package/dist/lang/ast/time-utils.js +83 -0
- package/dist/lang/field-space.d.ts +157 -0
- package/dist/lang/field-space.js +651 -0
- package/dist/lang/field-utils.d.ts +5 -0
- package/dist/lang/field-utils.js +33 -0
- package/dist/lang/index.d.ts +9 -0
- package/dist/lang/index.js +22 -0
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +156 -0
- package/dist/lang/lib/Malloy/MalloyLexer.js +1163 -0
- package/dist/lang/lib/Malloy/MalloyListener.d.ts +2026 -0
- package/dist/lang/lib/Malloy/MalloyListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +1920 -0
- package/dist/lang/lib/Malloy/MalloyParser.js +11790 -0
- package/dist/lang/lib/Malloy/MalloyVisitor.d.ts +1276 -0
- package/dist/lang/lib/Malloy/MalloyVisitor.js +4 -0
- package/dist/lang/parse-log.d.ts +27 -0
- package/dist/lang/parse-log.js +41 -0
- package/dist/lang/parse-malloy.d.ts +245 -0
- package/dist/lang/parse-malloy.js +729 -0
- package/dist/lang/parse-to-ast.d.ts +156 -0
- package/dist/lang/parse-to-ast.js +945 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +10 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +136 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +9 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +97 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +83 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +375 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +172 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +34 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +64 -0
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/find-external-references.js +51 -0
- package/dist/lang/reference-list.d.ts +10 -0
- package/dist/lang/reference-list.js +80 -0
- package/dist/lang/space-field.d.ts +119 -0
- package/dist/lang/space-field.js +339 -0
- package/dist/lang/test/document-help-context-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-help-context-walker.spec.js +45 -0
- package/dist/lang/test/document-symbol-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-symbol-walker.spec.js +100 -0
- package/dist/lang/test/field-symbols.spec.d.ts +1 -0
- package/dist/lang/test/field-symbols.spec.js +172 -0
- package/dist/lang/test/parse.spec.d.ts +12 -0
- package/dist/lang/test/parse.spec.js +1936 -0
- package/dist/lang/test/test-translator.d.ts +38 -0
- package/dist/lang/test/test-translator.js +334 -0
- package/dist/lang/zone.d.ts +57 -0
- package/dist/lang/zone.js +97 -0
- package/dist/malloy.d.ts +1134 -0
- package/dist/malloy.js +2354 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.js +34 -0
- package/dist/model/malloy-query.d.ts +313 -0
- package/dist/model/malloy-query.js +2603 -0
- package/dist/model/malloy-types.d.ts +404 -0
- package/dist/model/malloy-types.js +242 -0
- package/dist/model/malloy_query.d.ts +353 -0
- package/dist/model/malloy_query.js +2990 -0
- package/dist/model/malloy_types.d.ts +502 -0
- package/dist/model/malloy_types.js +283 -0
- package/dist/model/sql-block.d.ts +11 -0
- package/dist/model/sql-block.js +38 -0
- package/dist/model/sql_block.d.ts +11 -0
- package/dist/model/sql_block.js +41 -0
- package/dist/model/utils.d.ts +21 -0
- package/dist/model/utils.js +84 -0
- package/dist/runtime-types.d.ts +116 -0
- package/dist/runtime-types.js +40 -0
- package/dist/runtime_types.d.ts +119 -0
- package/dist/runtime_types.js +15 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Malloy
|
|
2
|
+
|
|
3
|
+
Malloy is an experimental language for describing data relationships and transformations. It is both a semantic modeling language and a querying language that runs queries against a relational database. Malloy currently connects to BigQuery and Postgres, and natively supports DuckDB. We've built a Visual Studio Code extension to facilitate building Malloy data models, querying and transforming data, and creating simple visualizations and dashboards.
|
|
4
|
+
|
|
5
|
+
## Building applications or products in javascript with @malloydata/malloy
|
|
6
|
+
|
|
7
|
+
This package facilitates building the Malloy language - or the usage of data models or queries written in the Malloy language - into your product, data application, or website. The `@malloydata/malloy` library translates complex data operations written into the Malloy language into 1) SQL and 2) metadata. The SQL can be run against a database, and then combined with results and rendered or used in a varitey of ways.
|
|
8
|
+
|
|
9
|
+
## Show me an example!
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
import { Runtime } from "@malloydata/malloy";
|
|
13
|
+
import { DuckDBConnection } from "@malloydata/db-duckdb";
|
|
14
|
+
|
|
15
|
+
const connection = new DuckDBConnection("duckdb-example");
|
|
16
|
+
const runtime = new Runtime(files, connection);
|
|
17
|
+
|
|
18
|
+
runtime.loadModel("source: flights is table('duckdb:data/flights.parquet')")
|
|
19
|
+
|
|
20
|
+
const runner = runtime.loadQuery("query: flights->{group_by: flight_num}")
|
|
21
|
+
runner.run() // <- executes query, returns JSON of results
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Note: These APIs are still in beta and subject to change.
|
|
26
|
+
|
|
27
|
+
## What's actually going on here?
|
|
28
|
+
|
|
29
|
+
The `@malloydata/malloy` is basically a compiler that takes a few things as input - 1. Some text that defines a Malloy data model 2. Some text that defines a Malloy query and 3. Some schema information about the table(s) the query might run against. The compiler works by attempting to compile the data model, and stopping compilation when it needs to ask for things it requires to continue compilation. This "loop" is then re-initiated when you provide the compiler with the additional information, until a point when the compiler has all the information it needs to compile a Malloy query based on a data model.
|
|
30
|
+
|
|
31
|
+
In practice, much of this loop is handled by various database plugins:
|
|
32
|
+
|
|
33
|
+
- [DuckDB](https://github.com/looker-open-source/malloy/tree/main/packages/malloy-db-duckdb)
|
|
34
|
+
- [BigQuery](https://github.com/looker-open-source/malloy/tree/main/packages/malloy-db-bigquery)
|
|
35
|
+
- [Postgres](https://github.com/looker-open-source/malloy/tree/main/packages/malloy-db-postgres)
|
|
36
|
+
|
|
37
|
+
## Do you have any examples?
|
|
38
|
+
|
|
39
|
+
You can find a (very) simple example of writing a CLI for executing Malloy queries [here](https://github.com/looker-open-source/malloy/tree/main/demo/malloy-demo-bq-cli)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toAsyncGenerator<T>(startStreaming: (onError: (error: Error) => void, onData: (data: T) => void, onEnd: () => void) => void): AsyncIterableIterator<T>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.toAsyncGenerator = void 0;
|
|
16
|
+
async function* toAsyncGenerator(startStreaming) {
|
|
17
|
+
let done = false;
|
|
18
|
+
function getResults(startStreaming) {
|
|
19
|
+
let resolve;
|
|
20
|
+
const promise = new Promise((res) => {
|
|
21
|
+
resolve = res;
|
|
22
|
+
});
|
|
23
|
+
startStreaming((error) => {
|
|
24
|
+
resolve({ done: true, isError: true, error });
|
|
25
|
+
}, (data) => {
|
|
26
|
+
resolve({
|
|
27
|
+
done: false,
|
|
28
|
+
value: data,
|
|
29
|
+
isError: false,
|
|
30
|
+
next: new Promise((res) => {
|
|
31
|
+
resolve = res;
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
}, () => {
|
|
35
|
+
resolve({ done: true, isError: false });
|
|
36
|
+
});
|
|
37
|
+
return promise;
|
|
38
|
+
}
|
|
39
|
+
let next = getResults(startStreaming);
|
|
40
|
+
while (!done) {
|
|
41
|
+
const result = await next;
|
|
42
|
+
if (result.done) {
|
|
43
|
+
done = true;
|
|
44
|
+
if (result.isError) {
|
|
45
|
+
throw result.error;
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
next = result.next;
|
|
51
|
+
yield result.value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.toAsyncGenerator = toAsyncGenerator;
|
|
56
|
+
//# sourceMappingURL=connection_utils.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerDialect = exports.getDialect = void 0;
|
|
16
|
+
const postgres_1 = require("./postgres");
|
|
17
|
+
const standardsql_1 = require("./standardsql");
|
|
18
|
+
const dialectMap = new Map();
|
|
19
|
+
function getDialect(name) {
|
|
20
|
+
const d = dialectMap.get(name);
|
|
21
|
+
if (d === undefined) {
|
|
22
|
+
throw new Error(`Unknown Dialect ${name}`);
|
|
23
|
+
}
|
|
24
|
+
return d;
|
|
25
|
+
}
|
|
26
|
+
exports.getDialect = getDialect;
|
|
27
|
+
function registerDialect(d) {
|
|
28
|
+
dialectMap.set(d.name, d);
|
|
29
|
+
}
|
|
30
|
+
exports.registerDialect = registerDialect;
|
|
31
|
+
registerDialect(new postgres_1.PostgresDialect());
|
|
32
|
+
registerDialect(new standardsql_1.StandardSQLDialect());
|
|
33
|
+
//# sourceMappingURL=dialect-map.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AtomicFieldTypeInner, TimeFieldType, TimestampUnit, ExtractUnit, DialectFragment, TimeValue } from "..";
|
|
2
|
+
import { Expr, Sampling, StructDef, TypecastFragment } from "../model";
|
|
3
|
+
interface DialectField {
|
|
4
|
+
type: string;
|
|
5
|
+
sqlExpression: string;
|
|
6
|
+
sqlOutputName: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Someday this might be used to control how a function call in malloy is
|
|
10
|
+
* translated into a function call in SQL. Today this is just so that
|
|
11
|
+
* the expression compiler can know the output type of a function.
|
|
12
|
+
*/
|
|
13
|
+
export interface FunctionInfo {
|
|
14
|
+
returnType: AtomicFieldTypeInner;
|
|
15
|
+
}
|
|
16
|
+
export declare type DialectFieldList = DialectField[];
|
|
17
|
+
export declare abstract class Dialect {
|
|
18
|
+
abstract name: string;
|
|
19
|
+
abstract defaultNumberType: string;
|
|
20
|
+
abstract udfPrefix: string;
|
|
21
|
+
abstract hasFinalStage: boolean;
|
|
22
|
+
abstract stringTypeName: string;
|
|
23
|
+
abstract divisionIsInteger: boolean;
|
|
24
|
+
abstract supportsSumDistinctFunction: boolean;
|
|
25
|
+
abstract unnestWithNumbers: boolean;
|
|
26
|
+
protected abstract functionInfo: Record<string, FunctionInfo>;
|
|
27
|
+
abstract defaultSampling: Sampling;
|
|
28
|
+
abstract supportUnnestArrayAgg: boolean;
|
|
29
|
+
abstract supportsCTEinCoorelatedSubQueries: boolean;
|
|
30
|
+
abstract quoteTablePath(tablePath: string): string;
|
|
31
|
+
abstract sqlGroupSetTable(groupSetCount: number): string;
|
|
32
|
+
abstract sqlAnyValue(groupSet: number, fieldName: string): string;
|
|
33
|
+
abstract sqlAggregateTurtle(groupSet: number, fieldList: DialectFieldList, orderBy: string | undefined, limit: number | undefined): string;
|
|
34
|
+
abstract sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
35
|
+
abstract sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
36
|
+
abstract sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
37
|
+
abstract sqlUnnestAlias(source: string, alias: string, fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean): string;
|
|
38
|
+
abstract sqlSumDistinctHashedKey(sqlDistinctKey: string): string;
|
|
39
|
+
abstract sqlGenerateUUID(): string;
|
|
40
|
+
abstract sqlFieldReference(alias: string, fieldName: string, fieldType: string, isNested: boolean, isArray: boolean): string;
|
|
41
|
+
abstract sqlUnnestPipelineHead(isSingleton: boolean, sourceSQLExpression: string): string;
|
|
42
|
+
abstract sqlCreateFunction(id: string, funcText: string): string;
|
|
43
|
+
abstract sqlCreateFunctionCombineLastStage(lastStageName: string, structDef: StructDef): string;
|
|
44
|
+
abstract sqlCreateTableAsSelect(tableName: string, sql: string): string;
|
|
45
|
+
abstract sqlSelectAliasAsStruct(alias: string, physicalFieldNames: string[]): string;
|
|
46
|
+
sqlFinalStage(_lastStageName: string, _fields: string[]): string;
|
|
47
|
+
sqlDateToString(sqlDateExp: string): string;
|
|
48
|
+
abstract sqlMaybeQuoteIdentifier(identifier: string): string;
|
|
49
|
+
abstract sqlNow(): Expr;
|
|
50
|
+
abstract sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
51
|
+
abstract sqlExtract(sqlTime: TimeValue, units: ExtractUnit): Expr;
|
|
52
|
+
abstract sqlMeasureTime(from: TimeValue, to: TimeValue, units: TimestampUnit): Expr;
|
|
53
|
+
abstract sqlAlterTime(op: "+" | "-", expr: TimeValue, n: Expr, timeframe: TimestampUnit): Expr;
|
|
54
|
+
ignoreInProject(_fieldName: string): boolean;
|
|
55
|
+
abstract sqlCast(cast: TypecastFragment): Expr;
|
|
56
|
+
abstract sqlLiteralTime(timeString: string, type: TimeFieldType, timezone: string): string;
|
|
57
|
+
abstract sqlRegexpMatch(expr: Expr, regex: string): Expr;
|
|
58
|
+
getFunctionInfo(functionName: string): FunctionInfo | undefined;
|
|
59
|
+
dialectExpr(df: DialectFragment): Expr;
|
|
60
|
+
sqlSumDistinct(_key: string, _value: string): string;
|
|
61
|
+
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
62
|
+
sqlOrderBy(orderTerms: string[]): string;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Dialect = void 0;
|
|
16
|
+
class Dialect {
|
|
17
|
+
sqlFinalStage(_lastStageName, _fields) {
|
|
18
|
+
throw new Error("Dialect has no final Stage but called Anyway");
|
|
19
|
+
}
|
|
20
|
+
// default implementation will probably work most of the time
|
|
21
|
+
sqlDateToString(sqlDateExp) {
|
|
22
|
+
return `CAST(DATE(${sqlDateExp}) AS ${this.stringTypeName} )`;
|
|
23
|
+
}
|
|
24
|
+
// BigQuery has some fieldNames that are Pseudo Fields and shouldn't be
|
|
25
|
+
// included in projections.
|
|
26
|
+
ignoreInProject(_fieldName) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
getFunctionInfo(functionName) {
|
|
30
|
+
return this.functionInfo[functionName.toLowerCase()];
|
|
31
|
+
}
|
|
32
|
+
dialectExpr(df) {
|
|
33
|
+
switch (df.function) {
|
|
34
|
+
case "now":
|
|
35
|
+
return this.sqlNow();
|
|
36
|
+
case "timeDiff":
|
|
37
|
+
return this.sqlMeasureTime(df.left, df.right, df.units);
|
|
38
|
+
case "delta":
|
|
39
|
+
return this.sqlAlterTime(df.op, df.base, df.delta, df.units);
|
|
40
|
+
case "trunc":
|
|
41
|
+
return this.sqlTrunc(df.expr, df.units);
|
|
42
|
+
case "extract":
|
|
43
|
+
return this.sqlExtract(df.expr, df.units);
|
|
44
|
+
case "cast":
|
|
45
|
+
return this.sqlCast(df);
|
|
46
|
+
case "regexpMatch":
|
|
47
|
+
return this.sqlRegexpMatch(df.expr, df.regexp);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
sqlSumDistinct(_key, _value) {
|
|
51
|
+
return "sqlSumDistinct called bu not implemented";
|
|
52
|
+
}
|
|
53
|
+
sqlSampleTable(tableSQL, sample) {
|
|
54
|
+
if (sample !== undefined) {
|
|
55
|
+
throw new Error(`Sampling is not supported on dialect ${this.name}.`);
|
|
56
|
+
}
|
|
57
|
+
return tableSQL;
|
|
58
|
+
}
|
|
59
|
+
sqlOrderBy(orderTerms) {
|
|
60
|
+
return `ORDER BY ${orderTerms.join(",")}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Dialect = Dialect;
|
|
64
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2021 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* This program is free software; you can redistribute it and/or
|
|
6
|
+
* modify it under the terms of the GNU General Public License
|
|
7
|
+
* version 2 as published by the Free Software Foundation.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerDialect = exports.getDialect = void 0;
|
|
16
|
+
const _1 = require(".");
|
|
17
|
+
const postgres_1 = require("./postgres");
|
|
18
|
+
const standardsql_1 = require("./standardsql");
|
|
19
|
+
const dialectMap = new Map();
|
|
20
|
+
function getDialect(name) {
|
|
21
|
+
const d = dialectMap.get(name);
|
|
22
|
+
if (d === undefined) {
|
|
23
|
+
throw new Error(`Unknown Dialect ${name}`);
|
|
24
|
+
}
|
|
25
|
+
return d;
|
|
26
|
+
}
|
|
27
|
+
exports.getDialect = getDialect;
|
|
28
|
+
function registerDialect(d) {
|
|
29
|
+
dialectMap.set(d.name, d);
|
|
30
|
+
}
|
|
31
|
+
exports.registerDialect = registerDialect;
|
|
32
|
+
registerDialect(new postgres_1.PostgresDialect());
|
|
33
|
+
registerDialect(new standardsql_1.StandardSQLDialect());
|
|
34
|
+
registerDialect(new _1.DuckDBDialect());
|
|
35
|
+
//# sourceMappingURL=dialect_map.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimestampUnit, TimeValue, TypecastFragment } from "../model";
|
|
2
|
+
import { Dialect, DialectFieldList, FunctionInfo } from "./dialect";
|
|
3
|
+
export declare class DuckDBDialect extends Dialect {
|
|
4
|
+
name: string;
|
|
5
|
+
defaultNumberType: string;
|
|
6
|
+
hasFinalStage: boolean;
|
|
7
|
+
stringTypeName: string;
|
|
8
|
+
divisionIsInteger: boolean;
|
|
9
|
+
supportsSumDistinctFunction: boolean;
|
|
10
|
+
unnestWithNumbers: boolean;
|
|
11
|
+
defaultSampling: {
|
|
12
|
+
rows: number;
|
|
13
|
+
};
|
|
14
|
+
supportUnnestArrayAgg: boolean;
|
|
15
|
+
supportsCTEinCoorelatedSubQueries: boolean;
|
|
16
|
+
functionInfo: Record<string, FunctionInfo>;
|
|
17
|
+
get udfPrefix(): string;
|
|
18
|
+
quoteTablePath(tableName: string): string;
|
|
19
|
+
sqlGroupSetTable(groupSetCount: number): string;
|
|
20
|
+
sqlAnyValue(groupSet: number, fieldName: string): string;
|
|
21
|
+
mapFields(fieldList: DialectFieldList): string;
|
|
22
|
+
sqlAggregateTurtle(groupSet: number, fieldList: DialectFieldList, orderBy: string | undefined, limit: number | undefined): string;
|
|
23
|
+
sqlAnyValueTurtle(groupSet: number, fieldList: DialectFieldList): string;
|
|
24
|
+
sqlAnyValueLastTurtle(name: string, groupSet: number, sqlName: string): string;
|
|
25
|
+
sqlCoaleseMeasuresInline(groupSet: number, fieldList: DialectFieldList): string;
|
|
26
|
+
sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, _needDistinctKey: boolean): string;
|
|
27
|
+
sqlSumDistinctHashedKey(_sqlDistinctKey: string): string;
|
|
28
|
+
sqlGenerateUUID(): string;
|
|
29
|
+
sqlDateToString(sqlDateExp: string): string;
|
|
30
|
+
sqlFieldReference(alias: string, fieldName: string, _fieldType: string, _isNested: boolean, isArray: boolean): string;
|
|
31
|
+
sqlUnnestPipelineHead(isSingleton: boolean, sourceSQLExpression: string): string;
|
|
32
|
+
sqlCreateFunction(id: string, funcText: string): string;
|
|
33
|
+
sqlCreateFunctionCombineLastStage(lastStageName: string, structDef: StructDef): string;
|
|
34
|
+
sqlSelectAliasAsStruct(alias: string, physicalFieldNames: string[]): string;
|
|
35
|
+
sqlMaybeQuoteIdentifier(identifier: string): string;
|
|
36
|
+
sqlCreateTableAsSelect(_tableName: string, _sql: string): string;
|
|
37
|
+
getFunctionInfo(_functionName: string): FunctionInfo | undefined;
|
|
38
|
+
sqlMeasureTime(from: TimeValue, to: TimeValue, units: string): Expr;
|
|
39
|
+
sqlNow(): Expr;
|
|
40
|
+
sqlTrunc(sqlTime: TimeValue, units: TimestampUnit): Expr;
|
|
41
|
+
sqlExtract(from: TimeValue, units: ExtractUnit): Expr;
|
|
42
|
+
sqlAlterTime(op: "+" | "-", expr: TimeValue, n: Expr, timeframe: DateUnit): Expr;
|
|
43
|
+
sqlCast(cast: TypecastFragment): Expr;
|
|
44
|
+
sqlRegexpMatch(expr: Expr, regexp: string): Expr;
|
|
45
|
+
sqlLiteralTime(timeString: string, type: TimeFieldType, _timezone: string): string;
|
|
46
|
+
sqlSumDistinct(key: string, value: string): string;
|
|
47
|
+
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
48
|
+
sqlOrderBy(orderTerms: string[]): string;
|
|
49
|
+
}
|