Skip to content

Commit b82e938

Browse files
authored
Merge pull request #1560 from keboola/ms/dmd-285-bigquery-type-alias-test
New test of BigQuery data type aliases
2 parents bbb7423 + 75c149e commit b82e938

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"google/cloud-storage": "^1.27",
3333
"guzzlehttp/guzzle": "~7.0",
3434
"keboola/csv": "^1",
35-
"keboola/php-datatypes": "^7.0",
35+
"keboola/php-datatypes": "^8.0",
3636
"microsoft/azure-storage-blob": "^1.5",
3737
"psr/log": "^1.1|^2.0|^3.0",
3838
"symfony/filesystem": "^7.0||^6.0||^5.0||^4.0",

tests/Backend/Bigquery/TableDefinitionOperationsTest.php

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Generator;
66
use Google\Cloud\BigQuery\BigQueryClient;
77
use Keboola\Csv\CsvFile;
8+
use Keboola\Datatype\Definition\BaseType;
89
use Keboola\Datatype\Definition\Bigquery;
910
use Keboola\StorageApi\Client;
1011
use Keboola\StorageApi\ClientException;
@@ -2226,10 +2227,6 @@ public function failedOperationsProvider(): Generator
22262227

22272228
public function testCreateTableBasetypes(): void
22282229
{
2229-
$bucketId = $this->getTestBucketId(self::STAGE_IN);
2230-
$runId = $this->_client->generateRunId();
2231-
$this->_client->setRunId($runId);
2232-
22332230
$data = [
22342231
'name' => 'table_basetypes',
22352232
'primaryKeysNames' => ['id'],
@@ -2269,6 +2266,7 @@ public function testCreateTableBasetypes(): void
22692266
],
22702267
];
22712268

2269+
$bucketId = $this->getTestBucketId();
22722270
$runId = $this->_client->generateRunId();
22732271
$this->_client->setRunId($runId);
22742272

@@ -2352,4 +2350,56 @@ public function testCreateTableBasetypes(): void
23522350
],
23532351
], $tableDetail['definition']);
23542352
}
2353+
2354+
public function testCreateTableWithTypeAliases(): void
2355+
{
2356+
$aliases = [
2357+
'column_bigdecimal' => [Bigquery::TYPE_BIGDECIMAL, Bigquery::TYPE_BIGNUMERIC, BaseType::NUMERIC],
2358+
'column_bigint' => [Bigquery::TYPE_BIGINT, Bigquery::TYPE_INTEGER, BaseType::INTEGER],
2359+
'column_boolean' => [Bigquery::TYPE_BOOLEAN, Bigquery::TYPE_BOOL, BaseType::BOOLEAN],
2360+
'column_byteint' => [Bigquery::TYPE_BYTEINT, Bigquery::TYPE_INTEGER, BaseType::INTEGER],
2361+
'column_decimal' => [Bigquery::TYPE_DECIMAL, Bigquery::TYPE_NUMERIC, BaseType::NUMERIC],
2362+
'column_float' => [Bigquery::TYPE_FLOAT, Bigquery::TYPE_FLOAT64, BaseType::FLOAT],
2363+
'column_int' => [Bigquery::TYPE_INT, Bigquery::TYPE_INTEGER, BaseType::INTEGER],
2364+
'column_integer' => [Bigquery::TYPE_INTEGER, Bigquery::TYPE_INTEGER, BaseType::INTEGER],
2365+
'column_smallint' => [Bigquery::TYPE_SMALLINT, Bigquery::TYPE_INTEGER, BaseType::INTEGER],
2366+
'column_tinyint' => [Bigquery::TYPE_TINYINT, Bigquery::TYPE_INTEGER, BaseType::INTEGER],
2367+
];
2368+
2369+
$columns = [];
2370+
foreach ($aliases as $columnName => [$alias, , ]) {
2371+
$columns[] = [
2372+
'name' => $columnName,
2373+
'definition' => ['type' => $alias],
2374+
];
2375+
}
2376+
2377+
$data = [
2378+
'name' => 'table_type_aliases',
2379+
'columns' => $columns,
2380+
];
2381+
2382+
$bucketId = $this->getTestBucketId();
2383+
2384+
$runId = $this->_client->generateRunId();
2385+
$this->_client->setRunId($runId);
2386+
2387+
$newTableId = $this->_client->createTableDefinition($bucketId, $data);
2388+
$tableDetail = $this->_client->getTable($newTableId);
2389+
2390+
$expected = [];
2391+
foreach ($aliases as $columnName => [, $type, $baseType]) {
2392+
$expected[] = [
2393+
'name' => $columnName,
2394+
'definition' => [
2395+
'type' => $type,
2396+
'nullable' => true,
2397+
],
2398+
'basetype' => $baseType,
2399+
'canBeFiltered' => true,
2400+
];
2401+
}
2402+
2403+
$this->assertSame($expected, $tableDetail['definition']['columns']);
2404+
}
23552405
}

0 commit comments

Comments
 (0)