-
Notifications
You must be signed in to change notification settings - Fork 945
Fix CSI timestamp issue #8090
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
Merged
Merged
Fix CSI timestamp issue #8090
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a09512
parse timestamp, migrate schema
milaGGL 075a99e
resolve circular dependency
milaGGL 59bf988
add unit tests
milaGGL a6505ce
prettier
milaGGL e0e4e94
resolve comments
milaGGL 555314e
add index manager test
milaGGL 697062a
add changeset
milaGGL b273b0c
Merge branch 'master' into mila/fix-CSI-timestamp-issue
milaGGL 7fb399b
update changeset
milaGGL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/firestore': patch | ||
--- | ||
|
||
Fixed the CSI issue where indexing on timestamp fields leads to incorrect query results. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
packages/firestore/test/unit/index/firestore_index_value_writer.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0x00 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0x00 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { expect } from 'chai'; | ||
|
||
import { FirestoreIndexValueWriter } from '../../../src/index/firestore_index_value_writer'; | ||
import { IndexByteEncoder } from '../../../src/index/index_byte_encoder'; | ||
import { Timestamp } from '../../../src/lite-api/timestamp'; | ||
import { IndexKind } from '../../../src/model/field_index'; | ||
import type { Value } from '../../../src/protos/firestore_proto_api'; | ||
import { toTimestamp } from '../../../src/remote/serializer'; | ||
import { JSON_SERIALIZER } from '../local/persistence_test_helpers'; | ||
|
||
import { compare } from './ordered_code_writer.test'; | ||
|
||
describe('Firestore Index Value Writer', () => { | ||
function compareIndexEncodedValues( | ||
value1: Value, | ||
value2: Value, | ||
direction: IndexKind | ||
): number { | ||
const encoder1 = new IndexByteEncoder(); | ||
const encoder2 = new IndexByteEncoder(); | ||
FirestoreIndexValueWriter.INSTANCE.writeIndexValue( | ||
value1, | ||
encoder1.forKind(direction) | ||
); | ||
|
||
FirestoreIndexValueWriter.INSTANCE.writeIndexValue( | ||
value2, | ||
encoder2.forKind(direction) | ||
); | ||
|
||
return compare(encoder1.encodedBytes(), encoder2.encodedBytes()); | ||
} | ||
|
||
describe('can gracefully handle different format of timestamp', () => { | ||
it('can handle different format of timestamp', () => { | ||
const value1 = { timestampValue: '2016-01-02T10:20:50.850Z' }; | ||
const value2 = { timestampValue: '2016-01-02T10:20:50.850000Z' }; | ||
const value3 = { timestampValue: '2016-01-02T10:20:50.850000000Z' }; | ||
const value4 = { | ||
timestampValue: { seconds: 1451730050, nanos: 850000000 } | ||
}; | ||
const value5 = { | ||
timestampValue: toTimestamp( | ||
JSON_SERIALIZER, | ||
new Timestamp(1451730050, 850000000) | ||
) | ||
}; | ||
expect( | ||
compareIndexEncodedValues(value1, value2, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value3, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value4, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value5, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
|
||
expect( | ||
compareIndexEncodedValues(value1, value2, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value3, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value4, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value5, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
}); | ||
|
||
it('can handle timestamps with 0 nanoseconds', () => { | ||
const value1 = { timestampValue: '2016-01-02T10:20:50Z' }; | ||
const value2 = { timestampValue: '2016-01-02T10:20:50.000000000Z' }; | ||
const value3 = { timestampValue: { seconds: 1451730050, nanos: 0 } }; | ||
const value4 = { | ||
timestampValue: toTimestamp( | ||
JSON_SERIALIZER, | ||
new Timestamp(1451730050, 0) | ||
) | ||
}; | ||
expect( | ||
compareIndexEncodedValues(value1, value2, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value3, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value4, IndexKind.ASCENDING) | ||
).to.equal(0); | ||
|
||
expect( | ||
compareIndexEncodedValues(value1, value2, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value3, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
expect( | ||
compareIndexEncodedValues(value1, value4, IndexKind.DESCENDING) | ||
).to.equal(0); | ||
}); | ||
|
||
it('can compare timestamps with different formats', () => { | ||
const value1 = { timestampValue: '2016-01-02T10:20:50Z' }; | ||
const value2 = { timestampValue: '2016-01-02T10:20:50.000001Z' }; | ||
const value3 = { | ||
timestampValue: { seconds: 1451730050, nanos: 999999999 } | ||
}; | ||
const value4 = { | ||
timestampValue: toTimestamp( | ||
JSON_SERIALIZER, | ||
new Timestamp(1451730050, 1) | ||
) | ||
}; | ||
expect( | ||
compareIndexEncodedValues(value1, value2, IndexKind.ASCENDING) | ||
).to.equal(-1); | ||
expect( | ||
compareIndexEncodedValues(value1, value3, IndexKind.ASCENDING) | ||
).to.equal(-1); | ||
expect( | ||
compareIndexEncodedValues(value1, value4, IndexKind.ASCENDING) | ||
).to.equal(-1); | ||
expect( | ||
compareIndexEncodedValues(value2, value3, IndexKind.ASCENDING) | ||
).to.equal(-1); | ||
expect( | ||
compareIndexEncodedValues(value2, value4, IndexKind.ASCENDING) | ||
).to.equal(1); | ||
expect( | ||
compareIndexEncodedValues(value3, value4, IndexKind.ASCENDING) | ||
).to.equal(1); | ||
|
||
expect( | ||
compareIndexEncodedValues(value1, value2, IndexKind.DESCENDING) | ||
).to.equal(1); | ||
expect( | ||
compareIndexEncodedValues(value1, value3, IndexKind.DESCENDING) | ||
).to.equal(1); | ||
expect( | ||
compareIndexEncodedValues(value1, value4, IndexKind.DESCENDING) | ||
).to.equal(1); | ||
expect( | ||
compareIndexEncodedValues(value2, value3, IndexKind.DESCENDING) | ||
).to.equal(1); | ||
expect( | ||
compareIndexEncodedValues(value2, value4, IndexKind.DESCENDING) | ||
).to.equal(-1); | ||
expect( | ||
compareIndexEncodedValues(value3, value4, IndexKind.DESCENDING) | ||
).to.equal(-1); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.