Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: New Pipeline Stages #2236

Merged
merged 11 commits into from
Jan 17, 2025
32 changes: 0 additions & 32 deletions dev/src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
* @param other The constant value to add.
* @return A new `Expr` representing the addition operation.
*/
add(other: any): Add;

Check warning on line 128 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
add(other: any): Add {

Check warning on line 129 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (other instanceof Expr) {
return new Add(this, other);
}
Expand Down Expand Up @@ -157,8 +157,8 @@
* @param other The constant value to subtract.
* @return A new `Expr` representing the subtraction operation.
*/
subtract(other: any): Subtract;

Check warning on line 160 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
subtract(other: any): Subtract {

Check warning on line 161 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (other instanceof Expr) {
return new Subtract(this, other);
}
Expand Down Expand Up @@ -189,8 +189,8 @@
* @param other The constant value to multiply by.
* @return A new `Expr` representing the multiplication operation.
*/
multiply(other: any): Multiply;

Check warning on line 192 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
multiply(other: any): Multiply {

Check warning on line 193 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (other instanceof Expr) {
return new Multiply(this, other);
}
Expand Down Expand Up @@ -221,8 +221,8 @@
* @param other The constant value to divide by.
* @return A new `Expr` representing the division operation.
*/
divide(other: any): Divide;

Check warning on line 224 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
divide(other: any): Divide {

Check warning on line 225 in dev/src/expression.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (other instanceof Expr) {
return new Divide(this, other);
}
Expand Down Expand Up @@ -1942,38 +1942,6 @@
}
}

/**
* @beta
*/
export class Fields extends Expr implements Selectable {
MarkDuckworth marked this conversation as resolved.
Show resolved Hide resolved
exprType: ExprType = 'Field';
selectable = true as const;

private constructor(private fields: Field[]) {
super();
}

static of(name: string, ...others: string[]): Fields {
return new Fields([Field.of(name), ...others.map(Field.of)]);
}

static ofAll(): Fields {
return new Fields([]);
}

fieldList(): Field[] {
return this.fields.map(f => f);
}

_toProto(serializer: Serializer): api.IValue {
return {
arrayValue: {
values: this.fields.map(f => f._toProto(serializer)),
},
};
}
}

/**
* @beta
*
Expand Down
1 change: 0 additions & 1 deletion dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export {
Expr,
ExprWithAlias,
Field,
Fields,
Constant,
Function,
Ordering,
Expand Down
37 changes: 28 additions & 9 deletions dev/src/pipeline-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export class ExecutionUtil<AppModelType> {
enc,
callback
) => {
console.log(`Pipeline response: ${JSON.stringify(proto, null, 2)}`);
if (proto === NOOP_MESSAGE) {
callback(undefined);
return;
Expand Down Expand Up @@ -215,14 +214,20 @@ export class ExecutionUtil<AppModelType> {
// `toProto()` might throw an exception. We rely on the behavior of an
// async function to convert this exception into the rejected Promise we
// catch below.
const request = pipeline._toProto(
transactionOrReadTime,
explainOptions
);

console.log(
`Executing pipeline: \n ${JSON.stringify(request, null, 2)}`
);
const request: api.IExecutePipelineRequest = {
database: this._firestore.formattedName,
structuredPipeline: {
pipeline: pipeline._toProto(),
},
};

if (transactionOrReadTime instanceof Uint8Array) {
request.transaction = transactionOrReadTime;
} else if (transactionOrReadTime instanceof Timestamp) {
request.readTime = transactionOrReadTime.toProto().timestampValue;
} else if (transactionOrReadTime) {
request.newTransaction = transactionOrReadTime;
}

let streamActive: Deferred<boolean>;
do {
Expand Down Expand Up @@ -392,6 +397,20 @@ export function isFirestoreValue(obj: any): obj is api.IValue {
return false;
}

export function selectableToExpr(
selectable: firestore.Selectable | string
): Expr {
if (typeof selectable === 'string') {
return Field.of(selectable);
} else if (selectable instanceof Field) {
return selectable;
} else if (selectable instanceof ExprWithAlias) {
return selectable.expr;
} else {
throw new Error('unexpected selectable: ' + selectable);
}
}

export function toPipelineFilterCondition(
f: FilterInternal,
serializer: Serializer
Expand Down
Loading
Loading