@query-farm/vgi 0.35.0 → 0.36.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/dist/filter-pushdown/evaluate.d.ts +6 -0
- package/dist/index.js +21 -4
- package/dist/index.js.map +4 -4
- package/dist/worker-cf-entry.js +21 -4
- package/dist/worker-cf-entry.js.map +4 -4
- package/package.json +1 -1
- package/src/filter-pushdown/deserialize.ts +19 -1
- package/src/filter-pushdown/evaluate.ts +51 -2
|
@@ -27,4 +27,10 @@ export declare class PushdownFilters {
|
|
|
27
27
|
getColumnValues(columnName: string): unknown[] | null;
|
|
28
28
|
toSql(): string;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Render one predicate, projecting a bare boolean column onto its equality
|
|
32
|
+
* form first. Predicate positions are the root and the children of `and`/`or`
|
|
33
|
+
* — the shape that actually turns up is `other = x AND NOT flag`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function predicateToSql(expression: FilterExpression): string;
|
|
30
36
|
export declare function expressionToSql(expression: FilterExpression): string;
|
package/dist/index.js
CHANGED
|
@@ -3800,7 +3800,8 @@ function isBooleanExpression(expression) {
|
|
|
3800
3800
|
if (["comparison", "and", "or", "not", "is_null", "in", "runtime_filter", "call"].includes(expression.node)) {
|
|
3801
3801
|
return true;
|
|
3802
3802
|
}
|
|
3803
|
-
|
|
3803
|
+
const type = expressionType(expression);
|
|
3804
|
+
return type !== undefined && isBool(type);
|
|
3804
3805
|
}
|
|
3805
3806
|
function requiresSessionContext(expression) {
|
|
3806
3807
|
switch (expression.node) {
|
|
@@ -4245,7 +4246,19 @@ function expressionColumns(expression, output = new Map) {
|
|
|
4245
4246
|
}
|
|
4246
4247
|
return output;
|
|
4247
4248
|
}
|
|
4249
|
+
function booleanColumnLeaf(expression) {
|
|
4250
|
+
const column = (node) => node.node === "column_ref" && node.dataType !== undefined && isBool(node.dataType) ? node.columnName : undefined;
|
|
4251
|
+
if (expression.node === "not") {
|
|
4252
|
+
const name = column(expression.expression);
|
|
4253
|
+
return name === undefined ? undefined : { columnName: name, value: false };
|
|
4254
|
+
}
|
|
4255
|
+
const name = column(expression);
|
|
4256
|
+
return name === undefined ? undefined : { columnName: name, value: true };
|
|
4257
|
+
}
|
|
4248
4258
|
function discreteValues(expression, columnName) {
|
|
4259
|
+
const leaf = booleanColumnLeaf(expression);
|
|
4260
|
+
if (leaf && leaf.columnName === columnName)
|
|
4261
|
+
return [leaf.value];
|
|
4249
4262
|
if (expression.node === "comparison" && expression.op === "eq" /* EQ */) {
|
|
4250
4263
|
if (expression.left.node === "column_ref" && expression.left.columnName === columnName && expression.right.node === "literal")
|
|
4251
4264
|
return [expression.right.value];
|
|
@@ -4351,7 +4364,7 @@ class PushdownFilters {
|
|
|
4351
4364
|
return null;
|
|
4352
4365
|
}
|
|
4353
4366
|
toSql() {
|
|
4354
|
-
return this.predicates.map((predicate) =>
|
|
4367
|
+
return this.predicates.map((predicate) => predicateToSql(predicate.expression)).join(" AND ");
|
|
4355
4368
|
}
|
|
4356
4369
|
}
|
|
4357
4370
|
function quote(value) {
|
|
@@ -4365,6 +4378,10 @@ function quote(value) {
|
|
|
4365
4378
|
return `[${value.map(quote).join(", ")}]`;
|
|
4366
4379
|
return String(value);
|
|
4367
4380
|
}
|
|
4381
|
+
function predicateToSql(expression) {
|
|
4382
|
+
const leaf = booleanColumnLeaf(expression);
|
|
4383
|
+
return leaf ? `${leaf.columnName} = ${quote(leaf.value)}` : expressionToSql(expression);
|
|
4384
|
+
}
|
|
4368
4385
|
function expressionToSql(expression) {
|
|
4369
4386
|
switch (expression.node) {
|
|
4370
4387
|
case "column_ref":
|
|
@@ -4388,7 +4405,7 @@ function expressionToSql(expression) {
|
|
|
4388
4405
|
}
|
|
4389
4406
|
case "and":
|
|
4390
4407
|
case "or":
|
|
4391
|
-
return `(${expression.children.map(
|
|
4408
|
+
return `(${expression.children.map(predicateToSql).join(` ${expression.node.toUpperCase()} `)})`;
|
|
4392
4409
|
case "not":
|
|
4393
4410
|
return `(NOT ${expressionToSql(expression.expression)})`;
|
|
4394
4411
|
case "is_null":
|
|
@@ -13597,4 +13614,4 @@ export {
|
|
|
13597
13614
|
utf82 as utf8
|
|
13598
13615
|
};
|
|
13599
13616
|
|
|
13600
|
-
//# debugId=
|
|
13617
|
+
//# debugId=19F589EDB6611F0964756E2164756E21
|