Skip to content

Commit 71f8634

Browse files
committed
feat(php-datatypes) New BigQuery alias FLOAT, BOOL
New aliases FLOAT for FLOAT64, BOOLEAN for BOOL. - It's not in documentation (https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric_types) but works in SQL. - It's in REST API documentation (https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#TableFieldSchema) and based on my observations REST API returns only FLOAT or BOOLEAN.
1 parent a890589 commit 71f8634

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/Definition/Bigquery.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Bigquery extends Common
3737

3838
public const TYPE_ARRAY = 'ARRAY';
3939

40+
// BOOL
4041
public const TYPE_BOOL = 'BOOL'; // NULL,TRUE,FALSE
42+
public const TYPE_BOOLEAN = 'BOOLEAN'; // REST API alias
4143

4244
public const TYPE_BYTES = 'BYTES'; // BYTES(L) L is a positive INT64
4345

@@ -71,7 +73,9 @@ class Bigquery extends Common
7173
// alias for BIGNUMERIC
7274
public const TYPE_BIGDECIMAL = 'BIGDECIMAL';
7375

76+
// FLOAT64
7477
public const TYPE_FLOAT64 = 'FLOAT64';
78+
public const TYPE_FLOAT = 'FLOAT'; // REST API alias
7579

7680
public const TYPE_STRING = 'STRING'; // STRING(L) L is a positive INT64 value
7781

@@ -114,6 +118,8 @@ class Bigquery extends Common
114118
self::TYPE_BYTEINT,
115119
self::TYPE_DECIMAL,
116120
self::TYPE_BIGDECIMAL,
121+
self::TYPE_FLOAT,
122+
self::TYPE_BOOLEAN,
117123
];
118124

119125
/* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#TableFieldSchema */
@@ -224,9 +230,11 @@ public function getBasetype(): string
224230
$basetype = BaseType::NUMERIC;
225231
break;
226232
case self::TYPE_FLOAT64:
233+
case self::TYPE_FLOAT:
227234
$basetype = BaseType::FLOAT;
228235
break;
229236
case self::TYPE_BOOL:
237+
case self::TYPE_BOOLEAN:
230238
$basetype = BaseType::BOOLEAN;
231239
break;
232240
case self::TYPE_DATE:
@@ -295,6 +303,8 @@ public function getBackendBasetype(): string
295303
self::TYPE_BYTEINT => self::TYPE_INTEGER,
296304
self::TYPE_DECIMAL => self::TYPE_NUMERIC,
297305
self::TYPE_BIGDECIMAL => self::TYPE_BIGNUMERIC,
306+
self::TYPE_FLOAT => self::TYPE_FLOAT64,
307+
self::TYPE_BOOLEAN => self::TYPE_BOOL,
298308
default => $this->type
299309
};
300310
}

tests/BigqueryDatatypeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function invalidLengths(): array
5353
['bigdecimal', '78'],
5454

5555
['bool', 'anyLength'],
56+
['boolean', 'anyLength'],
5657
['bytes', 'anyLength'],
5758
['date', 'anyLength'],
5859
['datetime', 'anyLength'],
@@ -69,6 +70,7 @@ public function invalidLengths(): array
6970
['tinyint', 'anyLength'],
7071
['byteint', 'anyLength'],
7172
['float64', 'anyLength'],
73+
['float', 'anyLength'],
7274
];
7375
}
7476

@@ -110,9 +112,11 @@ public function testBasetypes(): void
110112
$this->assertEquals(BaseType::NUMERIC, $basetype);
111113
break;
112114
case 'FLOAT64':
115+
case 'FLOAT':
113116
$this->assertEquals(BaseType::FLOAT, $basetype);
114117
break;
115118
case 'BOOL':
119+
case 'BOOLEAN':
116120
$this->assertEquals(BaseType::BOOLEAN, $basetype);
117121
break;
118122
case 'DATE':
@@ -333,6 +337,7 @@ public function validLengths(): array
333337
['bignumeric', '76,38'],
334338

335339
['bool', null],
340+
['boolean', null],
336341
['date', null],
337342
['datetime', null],
338343
['time', null],
@@ -348,6 +353,7 @@ public function validLengths(): array
348353
['tinyint', null],
349354
['byteint', null],
350355
['float64', null],
356+
['float', null],
351357
];
352358
}
353359

@@ -498,6 +504,8 @@ public function provideTestGetTypeFromAlias(): Generator
498504
Bigquery::TYPE_BYTEINT => Bigquery::TYPE_INTEGER,
499505
Bigquery::TYPE_DECIMAL => Bigquery::TYPE_NUMERIC,
500506
Bigquery::TYPE_BIGDECIMAL => Bigquery::TYPE_BIGNUMERIC,
507+
Bigquery::TYPE_FLOAT => Bigquery::TYPE_FLOAT64,
508+
Bigquery::TYPE_BOOLEAN => Bigquery::TYPE_BOOL,
501509
default => $type,
502510
};
503511

0 commit comments

Comments
 (0)