-
Notifications
You must be signed in to change notification settings - Fork 55
Big int #847
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
base: main
Are you sure you want to change the base?
Big int #847
Changes from all commits
af321ee
3137084
b5c7447
bd14576
acfeae1
07358a5
909d8a5
f2acd8c
602eefc
14828d9
080de0e
73e917e
ef5c779
4490a49
4c5aeb1
8137486
b87cf3a
ad89dab
5ee5d1b
38e31f4
cafb353
dbe3537
ba45e22
75a7f28
946b841
fafacee
fe3bf72
d3282bc
1761511
0e43fd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -896,6 +896,16 @@ public function getLimitForInt(): int | |
| return 4294967295; | ||
| } | ||
|
|
||
| /** | ||
| * Get max BIGINT limit | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getLimitForBigInt(): int | ||
| { | ||
| return Database::MAX_BIG_INT; | ||
|
Contributor
Author
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. Here going other way around |
||
| } | ||
ArnabChatterjee20k marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Get maximum column limit. | ||
| * https://mariadb.com/kb/en/innodb-limitations/#limitations-on-schema | ||
|
|
@@ -1164,6 +1174,10 @@ public function getAttributeWidth(Document $collection): int | |
| } | ||
| break; | ||
|
|
||
| case Database::VAR_BIGINT: | ||
| $total += 8; // BIGINT 8 bytes | ||
| break; | ||
|
|
||
| case Database::VAR_FLOAT: | ||
| $total += 8; // DOUBLE 8 bytes | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| use Utopia\Database\Validator\Attribute as AttributeValidator; | ||
| use Utopia\Database\Validator\Authorization; | ||
| use Utopia\Database\Validator\Authorization\Input; | ||
| use Utopia\Database\Validator\BigInt as BigIntValidator; | ||
| use Utopia\Database\Validator\Index as IndexValidator; | ||
| use Utopia\Database\Validator\IndexDependency as IndexDependencyValidator; | ||
| use Utopia\Database\Validator\PartialStructure; | ||
|
|
@@ -42,6 +43,7 @@ class Database | |
| // Simple Types | ||
| public const VAR_STRING = 'string'; | ||
| public const VAR_INTEGER = 'integer'; | ||
| public const VAR_BIGINT = 'bigint'; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public const VAR_FLOAT = 'double'; | ||
| public const VAR_BOOLEAN = 'boolean'; | ||
| public const VAR_DATETIME = 'datetime'; | ||
|
|
@@ -2512,6 +2514,7 @@ private function validateAttribute( | |
| maxStringLength: $this->adapter->getLimitForString(), | ||
| maxVarcharLength: $this->adapter->getMaxVarcharLength(), | ||
| maxIntLength: $this->adapter->getLimitForInt(), | ||
| maxBigIntLength: $this->adapter->getLimitForBigInt(), | ||
| supportForSchemaAttributes: $this->adapter->getSupportForSchemaAttributes(), | ||
| supportForVectors: $this->adapter->getSupportForVectors(), | ||
| supportForSpatialAttributes: $this->adapter->getSupportForSpatialAttributes(), | ||
|
|
@@ -2521,6 +2524,7 @@ private function validateAttribute( | |
| filterCallback: fn ($id) => $this->adapter->filter($id), | ||
| isMigrating: $this->isMigrating(), | ||
| sharedTables: $this->getSharedTables(), | ||
| supportUnsignedBigInt: $this->adapter->getSupportForUnsignedBigInt(), | ||
| ); | ||
|
|
||
| $validator->isValid($attribute); | ||
|
|
@@ -2588,6 +2592,11 @@ protected function validateDefaultTypes(string $type, mixed $default): void | |
| throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type); | ||
| } | ||
| break; | ||
| case Database::VAR_BIGINT: | ||
| if ($defaultType !== 'integer' && $defaultType !== 'string') { | ||
| throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type); | ||
| } | ||
| break; | ||
| case self::VAR_DATETIME: | ||
| if ($defaultType !== self::VAR_STRING) { | ||
| throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type); | ||
|
|
@@ -2607,6 +2616,7 @@ protected function validateDefaultTypes(string $type, mixed $default): void | |
| self::VAR_MEDIUMTEXT, | ||
| self::VAR_LONGTEXT, | ||
| self::VAR_INTEGER, | ||
| self::VAR_BIGINT, | ||
| self::VAR_FLOAT, | ||
| self::VAR_BOOLEAN, | ||
| self::VAR_DATETIME, | ||
|
|
@@ -2909,6 +2919,16 @@ public function updateAttribute(string $collection, string $id, ?string $type = | |
| throw new DatabaseException('Max size allowed for int is: ' . number_format($limit)); | ||
| } | ||
| break; | ||
| case self::VAR_BIGINT: | ||
| $sizeString = BigIntValidator::normalizeUnsignedString((string)$size); | ||
| $limit = (!$signed && $this->adapter->getSupportForUnsignedBigInt()) | ||
| ? BigIntValidator::UNSIGNED_MAX | ||
| : BigIntValidator::SIGNED_MAX; | ||
|
|
||
| if (BigIntValidator::compareUnsignedStrings($sizeString, $limit) > 0) { | ||
| throw new DatabaseException('Max size allowed for bigint is: ' . BigIntValidator::formatIntegerString($limit)); | ||
| } | ||
| break; | ||
| case self::VAR_FLOAT: | ||
| case self::VAR_BOOLEAN: | ||
| case self::VAR_DATETIME: | ||
|
|
@@ -2975,6 +2995,7 @@ public function updateAttribute(string $collection, string $id, ?string $type = | |
| self::VAR_MEDIUMTEXT, | ||
| self::VAR_LONGTEXT, | ||
| self::VAR_INTEGER, | ||
| self::VAR_BIGINT, | ||
| self::VAR_FLOAT, | ||
| self::VAR_BOOLEAN, | ||
| self::VAR_DATETIME, | ||
|
|
@@ -3137,7 +3158,7 @@ public function updateAttribute(string $collection, string $id, ?string $type = | |
| $collection, | ||
| $newKey ?? $id, | ||
| $originalType, | ||
| $originalSize, | ||
| (int)$originalSize, | ||
| $originalSigned, | ||
| $originalArray, | ||
| $originalKey, | ||
|
|
@@ -5577,7 +5598,9 @@ public function createDocument(string $collection, Document $document): Document | |
| $this->adapter->getIdAttributeType(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| null, | ||
|
Member
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. Do we need to pass the adapter values here
Contributor
Author
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. yes cause mongodb, postgres, sqlite doesn't support unsigned bigint |
||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
| if (!$structure->isValid($document)) { | ||
| throw new StructureException($structure->getDescription()); | ||
|
|
@@ -5685,7 +5708,9 @@ public function createDocuments( | |
| $this->adapter->getIdAttributeType(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| null, | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
| if (!$validator->isValid($document)) { | ||
| throw new StructureException($validator->getDescription()); | ||
|
|
@@ -6257,7 +6282,8 @@ public function updateDocument(string $collection, string $id, Document $documen | |
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes(), | ||
| $old | ||
| $old, | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
| if (!$structureValidator->isValid($document)) { // Make sure updated structure still apply collection rules (if any) | ||
| throw new StructureException($structureValidator->getDescription()); | ||
|
|
@@ -6378,7 +6404,8 @@ public function updateDocuments( | |
| $this->adapter->getMaxUIDLength(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
|
|
||
| if (!$validator->isValid($queries)) { | ||
|
|
@@ -6423,7 +6450,8 @@ public function updateDocuments( | |
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes(), | ||
| null // No old document available in bulk updates | ||
| null, // No old document available in bulk updates | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
|
|
||
| if (!$validator->isValid($updates)) { | ||
|
|
@@ -7269,7 +7297,8 @@ public function upsertDocumentsWithIncrease( | |
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes(), | ||
| $old->isEmpty() ? null : $old | ||
| $old->isEmpty() ? null : $old, | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
|
|
||
| if (!$validator->isValid($document)) { | ||
|
|
@@ -7423,6 +7452,7 @@ public function increaseDocumentAttribute( | |
|
|
||
| $whiteList = [ | ||
| self::VAR_INTEGER, | ||
| self::VAR_BIGINT, | ||
| self::VAR_FLOAT | ||
| ]; | ||
|
|
||
|
|
@@ -7521,6 +7551,7 @@ public function decreaseDocumentAttribute( | |
|
|
||
| $whiteList = [ | ||
| self::VAR_INTEGER, | ||
| self::VAR_BIGINT, | ||
| self::VAR_FLOAT | ||
| ]; | ||
|
|
||
|
|
@@ -8084,7 +8115,8 @@ public function deleteDocuments( | |
| $this->adapter->getMaxUIDLength(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
|
|
||
| if (!$validator->isValid($queries)) { | ||
|
|
@@ -8306,7 +8338,8 @@ public function find(string $collection, array $queries = [], string $forPermiss | |
| $this->adapter->getMaxUIDLength(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
| if (!$validator->isValid($queries)) { | ||
| throw new QueryException($validator->getDescription()); | ||
|
|
@@ -8562,7 +8595,8 @@ public function count(string $collection, array $queries = [], ?int $max = null) | |
| $this->adapter->getMaxUIDLength(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
| if (!$validator->isValid($queries)) { | ||
| throw new QueryException($validator->getDescription()); | ||
|
|
@@ -8635,7 +8669,8 @@ public function sum(string $collection, string $attribute, array $queries = [], | |
| $this->adapter->getMaxUIDLength(), | ||
| $this->adapter->getMinDateTime(), | ||
| $this->adapter->getMaxDateTime(), | ||
| $this->adapter->getSupportForAttributes() | ||
| $this->adapter->getSupportForAttributes(), | ||
| $this->adapter->getSupportForUnsignedBigInt() | ||
| ); | ||
| if (!$validator->isValid($queries)) { | ||
| throw new QueryException($validator->getDescription()); | ||
|
|
@@ -8900,6 +8935,7 @@ public function casting(Document $collection, Document $document): Document | |
| foreach ($attributes as $attribute) { | ||
| $key = $attribute['$id'] ?? ''; | ||
| $type = $attribute['type'] ?? ''; | ||
| $signed = $attribute['signed'] ?? true; | ||
| $array = $attribute['array'] ?? false; | ||
| $value = $document->getAttribute($key, null); | ||
| if (is_null($value)) { | ||
|
|
@@ -8932,6 +8968,11 @@ public function casting(Document $collection, Document $document): Document | |
| case self::VAR_INTEGER: | ||
| $node = (int)$node; | ||
| break; | ||
| case self::VAR_BIGINT: | ||
| if (\is_string($node) && BigIntValidator::fitsPhpInt($node, $signed)) { | ||
| $node = (int)$node; | ||
| } | ||
| break; | ||
| case self::VAR_FLOAT: | ||
| $node = (float)$node; | ||
| break; | ||
|
|
@@ -8948,7 +8989,6 @@ public function casting(Document $collection, Document $document): Document | |
| return $document; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Encode Attribute | ||
| * | ||
|
|
||
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.
mongodb, postgresql, sqlite doesn't support unsigned bigint