Skip to content
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

BIG-203 Convert types not supported in BQ REST API #124

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/php-datatypes/src/Definition/Bigquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ class Bigquery extends Common
public const TYPE_STRING = 'STRING'; // STRING(L) L is a positive INT64 value

public const TYPE_STRUCT = 'STRUCT';

// Map of types available in SQL api but not supported by REST API
// Most of them are aliases for other types
public const REST_API_TYPES_MAP = [
self::TYPE_INT => self::TYPE_INT64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ale co ARRAY a INTERVAL ?

image

myslim, ze oba tyto typy nemame dobre uchopene v connection. array by mel prijit s definici a interval taky. Imho bychom to meli zakazat na request objectu. Toto bych ale shipnul a na ten array a interval zalozil dalsi task

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array je repeated record a interval nemá dokumentaci pro REST API ani, takže sem ho zatím přeskočil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jo, ale kdyz to sem dorazi, tak to nekde nejak neplanovane vyhuci. Takze bychom to meli imho odchytit uz nekde v connection. Takze to bude chtit nejakou dalsi praci

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::TYPE_SMALLINT => self::TYPE_INT64,
self::TYPE_BIGINT => self::TYPE_INT64,
self::TYPE_TINYINT => self::TYPE_INT64,
self::TYPE_BYTEINT => self::TYPE_INT64,
self::TYPE_DECIMAL => self::TYPE_NUMERIC,
self::TYPE_BIGDECIMAL => self::TYPE_BIGNUMERIC,
];
public const TYPES = [
self::TYPE_ARRAY,
self::TYPE_BOOL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static function convertColumnToRestFormat(BigqueryColumn $column): array
// others
$schema = [
'name' => $column->getColumnName(),
'type' => $definition->getType(),
'type' => self::getRestTypeForType($definition->getType()),
];
$schema = self::updateSchemaLength($definition->getLength(), $schema);
if ($definition->isNullable() === false) {
Expand All @@ -204,4 +204,12 @@ public static function convertColumnToRestFormat(BigqueryColumn $column): array
/** @phpstan-var BigqueryTableFieldSchema */
return $schema;
}

private static function getRestTypeForType(string $type): string
{
if (array_key_exists($type, Bigquery::REST_API_TYPES_MAP)) {
return Bigquery::REST_API_TYPES_MAP[$type];
}
return $type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,77 @@ public function definitions(): Generator
],
],
];
// aliases
yield 'INT' => [
'type' => Bigquery::TYPE_INT,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'INT64',
],
];
yield 'SMALLINT' => [
'type' => Bigquery::TYPE_SMALLINT,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'INT64',
],
];
yield 'BIGINT' => [
'type' => Bigquery::TYPE_BIGINT,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'INT64',
],
];
yield 'TINYINT' => [
'type' => Bigquery::TYPE_TINYINT,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'INT64',
],
];
yield 'BYTEINT' => [
'type' => Bigquery::TYPE_BYTEINT,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'INT64',
],
];
yield 'DECIMAL' => [
'type' => Bigquery::TYPE_DECIMAL,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'NUMERIC',
],
];
yield 'BIGDECIMAL' => [
'type' => Bigquery::TYPE_BIGDECIMAL,
'length' => null,
'default' => null,
'nullable' => true,
'expected' => [
'name' => 'myCol',
'type' => 'BIGNUMERIC',
],
];
}

/**
Expand Down
Loading