-
Notifications
You must be signed in to change notification settings - Fork 333
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
Fix issue of returning incorrect entities when querying table with int64 values #2386
Merged
Merged
Changes from all commits
Commits
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 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
95 changes: 95 additions & 0 deletions
95
src/table/persistence/QueryInterpreter/QueryNodes/BigNumberNode.ts
This file contains 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,95 @@ | ||
import { IQueryContext } from "../IQueryContext"; | ||
import IQueryNode from "./IQueryNode"; | ||
import ValueNode from "./ValueNode"; | ||
|
||
/** | ||
* Represents a constant value which is stored in its underlying JavaScript representation. | ||
* | ||
* This is used to hold boolean, number, and string values that are provided in the query. | ||
* For example, the query `PartitionKey eq 'foo'` would contain a `ConstantNode` with the value `foo`. | ||
*/ | ||
export default class BigNumberNode extends ValueNode { | ||
get name(): string { | ||
return "BigNumber"; | ||
} | ||
|
||
compare(context: IQueryContext, other: IQueryNode): number { | ||
const thisValue = this.evaluate(context) as string; | ||
const otherValue = other.evaluate(context) as string; | ||
|
||
if (thisValue === undefined || otherValue === undefined || otherValue === null) { | ||
return NaN; | ||
} | ||
|
||
if (thisValue.startsWith("-")) { | ||
// Compare two negative number | ||
if (otherValue.startsWith("-")) { | ||
return -(this.comparePositiveNumber(thisValue.substring(1), otherValue.substring(1))); | ||
} | ||
else { | ||
// Could be two 0s formated with -000 and 000 | ||
if (this.trimZeros(thisValue.substring(1)).length === 0 | ||
&& this.trimZeros(otherValue).length === 0) { | ||
return 0; | ||
} | ||
else { | ||
return -1; | ||
} | ||
} | ||
} | ||
else { | ||
// Could be two 0s formated with -000 and 000 | ||
if (otherValue.startsWith("-")) { | ||
if (this.trimZeros(thisValue.substring(1)).length === 0 | ||
&& this.trimZeros(otherValue).length === 0) { | ||
return 0; | ||
} | ||
else { | ||
return 1; | ||
} | ||
} | ||
else { | ||
return this.comparePositiveNumber(thisValue, otherValue); | ||
} | ||
} | ||
} | ||
|
||
comparePositiveNumber(thisValue: string, otherValue: string): number { | ||
const thisNumberValue = this.trimZeros(thisValue); | ||
const otherNumberValue = this.trimZeros(otherValue); | ||
|
||
if (thisNumberValue.length < otherNumberValue.length) { | ||
return -1 | ||
} | ||
else if (thisNumberValue.length > otherNumberValue.length) { | ||
return 1; | ||
} | ||
|
||
let index = 0; | ||
while (index < thisNumberValue.length) { | ||
if (thisNumberValue[index] < otherNumberValue[index]) { | ||
return -1; | ||
} | ||
else if (thisNumberValue[index] > otherNumberValue[index]) { | ||
return 1; | ||
} | ||
++index | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
trimZeros(numberString: string): string { | ||
let index = 0; | ||
while (index < numberString.length) { | ||
if (numberString[index] === '0') { | ||
++index; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
|
||
return numberString.substring(index); | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
|
@@ -260,12 +260,12 @@ describe("Query Parser", () => { | |
{ | ||
name: "Correctly handles longs", | ||
originalQuery: "myInt lt 123.01L", | ||
expectedQuery: "(lt (id myInt) \"123.01\")" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: We might can add a case to validate long query here. Might can do it after this release, as the test case already covered long. |
||
expectedQuery: "(lt (id myInt) (BigNumber 123.01))" | ||
}, | ||
{ | ||
name: "Correctly handles longs with a negative sign", | ||
originalQuery: "myInt gt -123.01L", | ||
expectedQuery: "(gt (id myInt) \"-123.01\")" | ||
expectedQuery: "(gt (id myInt) (BigNumber -123.01))" | ||
} | ||
]) | ||
|
||
|
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to check the entity will have value as "1234L"?