Skip to content

Commit 75c149e

Browse files
committed
test(bigquery) Check type alias mapping
- BigQuery allows to use aliases for data types. We need to check if aliases are really working on BQ side and are correctly mapped to our base types. - New aliases FLOAT and BOOLEAN added in keboola/storage-backend#231.
1 parent a41c9a1 commit 75c149e

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

tests/Backend/Bigquery/TableDefinitionOperationsTest.php

Lines changed: 53 additions & 0 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;
@@ -2349,4 +2350,56 @@ public function testCreateTableBasetypes(): void
23492350
],
23502351
], $tableDetail['definition']);
23512352
}
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+
}
23522405
}

0 commit comments

Comments
 (0)