Skip to content

Commit 0b2845a

Browse files
Pipeline fix tests and exports (#9342)
* clean up exports and imports * Fix implementation of Query to Pipeline for isNan, isNotNan, isNull, and isNotNull changes in the backend * fix tests to accomodate for backend changes to multiple sort stages * another test that the console usage will perform runtime validation of user data * formatting * Copy the latest pipelines tests into lite api pipelines tests. Fix a few minor bugs in the lite pipeline implementation * Remove special handling of null and nan in query to pipeline * remove function expresssions isNan, isNull, isNotNan, isNotNull, and error * Renamed len function to length, with a fix to the prune-dts script * lastest API review md files * fixed title is not null test
1 parent 07ca9c6 commit 0b2845a

File tree

13 files changed

+2123
-893
lines changed

13 files changed

+2123
-893
lines changed

common/api-review/firestore-lite-pipelines.api.md

Lines changed: 277 additions & 38 deletions
Large diffs are not rendered by default.

common/api-review/firestore-pipelines.api.md

Lines changed: 20 additions & 133 deletions
Large diffs are not rendered by default.

integration/firestore/gulpfile.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ if (typeof process === 'undefined') {
7070
)
7171
)
7272
.pipe(
73-
replace(
74-
/**
75-
* This regex is designed to match the Firebase import in our
76-
* integration tests.
77-
*/
78-
/\s+from '\.(\.\/util)?\/pipeline_export';/,
79-
` from '${resolve(__dirname, './pipeline_export')}';
73+
replace(
74+
/**
75+
* This regex is designed to match the Firebase import in our
76+
* integration tests.
77+
*/
78+
/\s+from '\.(\.\/util)?\/pipeline_export';/,
79+
` from '${resolve(__dirname, './pipeline_export')}';
8080
8181
if (typeof process === 'undefined') {
8282
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
8383
} else {
8484
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
8585
}
8686
`
87-
)
87+
)
8888
)
8989
.pipe(
9090
/**

packages/firestore/lite/pipelines/pipelines.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ export {
102102
isError,
103103
or,
104104
divide,
105-
isNotNan,
106105
map,
107-
isNotNull,
108-
isNull,
109106
mod,
110107
documentId,
111108
equal,
@@ -128,7 +125,6 @@ export {
128125
logicalMaximum,
129126
logicalMinimum,
130127
exists,
131-
isNan,
132128
reverse,
133129
byteLength,
134130
charLength,
@@ -160,6 +156,27 @@ export {
160156
timestampSubtract,
161157
ascending,
162158
descending,
159+
arrayGet,
160+
abs,
161+
sum,
162+
countDistinct,
163+
ceil,
164+
floor,
165+
exp,
166+
pow,
167+
round,
168+
collectionId,
169+
ln,
170+
log,
171+
sqrt,
172+
stringReverse,
173+
log10,
174+
concat,
175+
currentTimestamp,
176+
ifAbsent,
177+
join,
178+
length,
179+
arraySum,
163180
AliasedExpression,
164181
Field,
165182
Constant,

packages/firestore/src/api_pipelines.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ export {
5353
SortStageOptions
5454
} from './lite-api/stage_options';
5555

56-
export {
57-
Stage,
58-
AddFields,
59-
Aggregate,
60-
Distinct,
61-
CollectionSource,
62-
CollectionGroupSource,
63-
DatabaseSource,
64-
DocumentsSource,
65-
Where,
66-
FindNearest,
67-
Limit,
68-
Offset,
69-
Select,
70-
Sort,
71-
RawStage
72-
} from './lite-api/stage';
73-
7456
export {
7557
field,
7658
constant,
@@ -98,7 +80,6 @@ export {
9880
logicalMaximum,
9981
logicalMinimum,
10082
exists,
101-
isNan,
10283
reverse,
10384
byteLength,
10485
charLength,
@@ -141,9 +122,6 @@ export {
141122
isError,
142123
ifError,
143124
isAbsent,
144-
isNull,
145-
isNotNull,
146-
isNotNan,
147125
map,
148126
mapRemove,
149127
mapMerge,
@@ -160,11 +138,10 @@ export {
160138
log,
161139
sqrt,
162140
stringReverse,
163-
length as len,
141+
length,
164142
abs,
165143
concat,
166144
currentTimestamp,
167-
error,
168145
ifAbsent,
169146
join,
170147
log10,
@@ -175,10 +152,7 @@ export {
175152
FunctionExpression,
176153
Ordering,
177154
BooleanExpression,
178-
AggregateFunction
179-
} from './lite-api/expressions';
180-
181-
export type {
155+
AggregateFunction,
182156
ExpressionType,
183157
AliasedAggregate,
184158
Selectable

packages/firestore/src/core/pipeline-util.ts

Lines changed: 66 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
} from '../lite-api/expressions';
2929
import { Pipeline } from '../lite-api/pipeline';
3030
import { doc } from '../lite-api/reference';
31-
import { isNanValue, isNullValue } from '../model/values';
3231
import { fail } from '../util/assert';
3332

3433
import { Bound } from './bound';
@@ -53,90 +52,76 @@ import {
5352
export function toPipelineBooleanExpr(f: FilterInternal): BooleanExpression {
5453
if (f instanceof FieldFilterInternal) {
5554
const fieldValue = field(f.field.toString());
56-
if (isNanValue(f.value)) {
57-
if (f.op === Operator.EQUAL) {
58-
return and(fieldValue.exists(), fieldValue.isNan());
59-
} else {
60-
return and(fieldValue.exists(), fieldValue.isNotNan());
55+
// Comparison filters
56+
const value = f.value;
57+
switch (f.op) {
58+
case Operator.LESS_THAN:
59+
return and(
60+
fieldValue.exists(),
61+
fieldValue.lessThan(Constant._fromProto(value))
62+
);
63+
case Operator.LESS_THAN_OR_EQUAL:
64+
return and(
65+
fieldValue.exists(),
66+
fieldValue.lessThanOrEqual(Constant._fromProto(value))
67+
);
68+
case Operator.GREATER_THAN:
69+
return and(
70+
fieldValue.exists(),
71+
fieldValue.greaterThan(Constant._fromProto(value))
72+
);
73+
case Operator.GREATER_THAN_OR_EQUAL:
74+
return and(
75+
fieldValue.exists(),
76+
fieldValue.greaterThanOrEqual(Constant._fromProto(value))
77+
);
78+
case Operator.EQUAL:
79+
return and(
80+
fieldValue.exists(),
81+
fieldValue.equal(Constant._fromProto(value))
82+
);
83+
case Operator.NOT_EQUAL:
84+
return and(
85+
fieldValue.exists(),
86+
fieldValue.notEqual(Constant._fromProto(value))
87+
);
88+
case Operator.ARRAY_CONTAINS:
89+
return and(
90+
fieldValue.exists(),
91+
fieldValue.arrayContains(Constant._fromProto(value))
92+
);
93+
case Operator.IN: {
94+
const values = value?.arrayValue?.values?.map((val: any) =>
95+
Constant._fromProto(val)
96+
);
97+
if (!values) {
98+
return and(fieldValue.exists(), fieldValue.equalAny([]));
99+
} else if (values.length === 1) {
100+
return and(fieldValue.exists(), fieldValue.equal(values[0]));
101+
} else {
102+
return and(fieldValue.exists(), fieldValue.equalAny(values));
103+
}
61104
}
62-
} else if (isNullValue(f.value)) {
63-
if (f.op === Operator.EQUAL) {
64-
return and(fieldValue.exists(), fieldValue.isNull());
65-
} else {
66-
return and(fieldValue.exists(), fieldValue.isNotNull());
105+
case Operator.ARRAY_CONTAINS_ANY: {
106+
const values = value?.arrayValue?.values?.map((val: any) =>
107+
Constant._fromProto(val)
108+
);
109+
return and(fieldValue.exists(), fieldValue.arrayContainsAny(values!));
67110
}
68-
} else {
69-
// Comparison filters
70-
const value = f.value;
71-
switch (f.op) {
72-
case Operator.LESS_THAN:
73-
return and(
74-
fieldValue.exists(),
75-
fieldValue.lessThan(Constant._fromProto(value))
76-
);
77-
case Operator.LESS_THAN_OR_EQUAL:
78-
return and(
79-
fieldValue.exists(),
80-
fieldValue.lessThanOrEqual(Constant._fromProto(value))
81-
);
82-
case Operator.GREATER_THAN:
83-
return and(
84-
fieldValue.exists(),
85-
fieldValue.greaterThan(Constant._fromProto(value))
86-
);
87-
case Operator.GREATER_THAN_OR_EQUAL:
88-
return and(
89-
fieldValue.exists(),
90-
fieldValue.greaterThanOrEqual(Constant._fromProto(value))
91-
);
92-
case Operator.EQUAL:
93-
return and(
94-
fieldValue.exists(),
95-
fieldValue.equal(Constant._fromProto(value))
96-
);
97-
case Operator.NOT_EQUAL:
98-
return and(
99-
fieldValue.exists(),
100-
fieldValue.notEqual(Constant._fromProto(value))
101-
);
102-
case Operator.ARRAY_CONTAINS:
103-
return and(
104-
fieldValue.exists(),
105-
fieldValue.arrayContains(Constant._fromProto(value))
106-
);
107-
case Operator.IN: {
108-
const values = value?.arrayValue?.values?.map((val: any) =>
109-
Constant._fromProto(val)
110-
);
111-
if (!values) {
112-
return and(fieldValue.exists(), fieldValue.equalAny([]));
113-
} else if (values.length === 1) {
114-
return and(fieldValue.exists(), fieldValue.equal(values[0]));
115-
} else {
116-
return and(fieldValue.exists(), fieldValue.equalAny(values));
117-
}
118-
}
119-
case Operator.ARRAY_CONTAINS_ANY: {
120-
const values = value?.arrayValue?.values?.map((val: any) =>
121-
Constant._fromProto(val)
122-
);
123-
return and(fieldValue.exists(), fieldValue.arrayContainsAny(values!));
124-
}
125-
case Operator.NOT_IN: {
126-
const values = value?.arrayValue?.values?.map((val: any) =>
127-
Constant._fromProto(val)
128-
);
129-
if (!values) {
130-
return and(fieldValue.exists(), fieldValue.notEqualAny([]));
131-
} else if (values.length === 1) {
132-
return and(fieldValue.exists(), fieldValue.notEqual(values[0]));
133-
} else {
134-
return and(fieldValue.exists(), fieldValue.notEqualAny(values));
135-
}
111+
case Operator.NOT_IN: {
112+
const values = value?.arrayValue?.values?.map((val: any) =>
113+
Constant._fromProto(val)
114+
);
115+
if (!values) {
116+
return and(fieldValue.exists(), fieldValue.notEqualAny([]));
117+
} else if (values.length === 1) {
118+
return and(fieldValue.exists(), fieldValue.notEqual(values[0]));
119+
} else {
120+
return and(fieldValue.exists(), fieldValue.notEqualAny(values));
136121
}
137-
default:
138-
fail(0x9047, 'Unexpected operator');
139122
}
123+
default:
124+
fail(0x9047, 'Unexpected operator');
140125
}
141126
} else if (f instanceof CompositeFilterInternal) {
142127
switch (f.op) {

0 commit comments

Comments
 (0)