-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue of returning incorrect entities when querying table with in…
…t64 values
- Loading branch information
Showing
6 changed files
with
117 additions
and
8 deletions.
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
61 changes: 61 additions & 0 deletions
61
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,61 @@ | ||
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; | ||
} | ||
|
||
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
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