Skip to content
Draft
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
37 changes: 16 additions & 21 deletions packages/php-db-import-export/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
parameters:
ignoreErrors:
-
message: "#^Method Keboola\\\\Db\\\\ImportExport\\\\Backend\\\\Bigquery\\\\BigqueryException\\:\\:createExceptionFromJobResult\\(\\) has parameter \\$jobInfo with no value type specified in iterable type array\\.$#"
count: 1
path: src/Backend/Bigquery/BigqueryException.php

-
message: "#^Method Keboola\\\\Db\\\\ImportExport\\\\Backend\\\\Bigquery\\\\BigqueryException\\:\\:getErrorMessageForErrorList\\(\\) has parameter \\$parsingErrors with no value type specified in iterable type array\\.$#"
count: 1
path: src/Backend/Bigquery/BigqueryException.php

-
message: "#^Cannot access offset 'durationSeconds' on mixed\\.$#"
count: 1
Expand All @@ -25,6 +35,11 @@ parameters:
count: 1
path: src/Backend/Snowflake/Importer.php

-
message: "#^Dead catch \\- Error is never thrown in the try block\\.$#"
count: 1
path: src/Backend/SourceDestinationColumnMap.php

-
message: "#^Method Keboola\\\\Db\\\\ImportExport\\\\Backend\\\\Synapse\\\\Exporter\\:\\:getAdapter\\(\\) should return Keboola\\\\Db\\\\ImportExport\\\\Backend\\\\Synapse\\\\SynapseExportAdapterInterface but returns object\\.$#"
count: 1
Expand Down Expand Up @@ -318,24 +333,4 @@ parameters:
-
message: "#^Variable \\$destination in PHPDoc tag @var does not match assigned variable \\$options\\.$#"
count: 1
path: tests/unit/Storage/ABS/SynapseExportAdapterTest.php

-
message: "#^Method Keboola\\\\Db\\\\ImportExport\\\\Backend\\\\Bigquery\\\\BigqueryException::createExceptionFromJobResult\\(\\) has parameter \\$jobInfo with no value type specified in iterable type array\\.$#"
count: 1
path: src/Backend/Bigquery/BigqueryException.php

-
message: "#^Method Keboola\\\\Db\\\\ImportExport\\\\Backend\\\\Bigquery\\\\BigqueryException::getErrorMessageForErrorList\\(\\) has parameter \\$parsingErrors with no value type specified in iterable type array\\.$#"
count: 1
path: src/Backend/Bigquery/BigqueryException.php

-
message: "#^Dead catch - Error is never thrown in the try block\\.$#"
count: 1
path: src/Backend/SourceDestinationColumnMap.php

-
message: "#^Result of callable callable\\(T\\): void \\(void\\) is used\\.$#"
count: 1
path: tests/Common/StubLoader/GCSLoader.php
path: tests/unit/Storage/ABS/SynapseExportAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BigqueryImportOptions extends ImportOptions
* @param self::USING_TYPES_* $usingTypes
* @param string[] $importAsNull
* @param string[] $features
* @param string[] $ignoreColumns
*/
public function __construct(
array $convertEmptyValuesToNull = [],
Expand All @@ -26,13 +27,15 @@ public function __construct(
?Session $session = null,
array $importAsNull = self::DEFAULT_IMPORT_AS_NULL,
array $features = [],
array $ignoreColumns = [],
) {
parent::__construct(
convertEmptyValuesToNull: $convertEmptyValuesToNull,
isIncremental: $isIncremental,
useTimestamp: $useTimestamp,
numberOfIgnoredLines: $numberOfIgnoredLines,
usingTypes: $usingTypes,
ignoreColumns: $ignoreColumns,
importAsNull: $importAsNull,
features: $features,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Keboola\Datatype\Definition\BaseType;
use Keboola\Datatype\Definition\Bigquery;
use Keboola\Db\Import\Exception;
use Keboola\Db\ImportExport\Backend\Bigquery\BigqueryImportOptions;
use Keboola\Db\ImportExport\Backend\SourceDestinationColumnMap;
use Keboola\Db\ImportExport\Backend\ToStageImporterInterface;
use Keboola\TableBackendUtils\Column\Bigquery\BigqueryColumn;
use Keboola\TableBackendUtils\Escaping\Bigquery\BigqueryQuote;
Expand All @@ -17,33 +17,6 @@ class SqlBuilder
{
private const SRC_ALIAS = 'src';

private function assertColumnExist(
BigqueryTableDefinition $tableDefinition,
BigqueryColumn $columnDefinition,
): BigqueryColumn {
$destinationColumn = null;
// case sensitive search
/** @var BigqueryColumn $col */
foreach ($tableDefinition->getColumnsDefinitions() as $col) {
if ($col->getColumnName() === $columnDefinition->getColumnName()) {
$destinationColumn = $col;
break;
}
}
if ($destinationColumn === null) {
throw new Exception(
sprintf(
'Columns "%s" can be imported as it was not found between columns "%s" of destination table.',
$columnDefinition->getColumnName(),
implode(', ', $tableDefinition->getColumnsNames()),
),
Exception::UNKNOWN_ERROR,
);
}

return $destinationColumn;
}

public function getBeginTransaction(): string
{
return 'BEGIN TRANSACTION';
Expand Down Expand Up @@ -88,13 +61,13 @@ public function getDropTableIfExistsCommand(
*/
private function getColumnSetSqlPartForStringTable(
BigqueryTableDefinition $sourceTableDefinition,
BigqueryTableDefinition $destinationTableDefinition,
SourceDestinationColumnMap $columnMap,
BigqueryImportOptions $importOptions,
): array {
$columnsSetSql = [];
/** @var BigqueryColumn $columnDefinition */
foreach ($sourceTableDefinition->getColumnsDefinitions() as $columnDefinition) {
$destinationColumn = $this->assertColumnExist($destinationTableDefinition, $columnDefinition);
$destinationColumn = $columnMap->getDestination($columnDefinition);
if (in_array($columnDefinition->getColumnName(), $importOptions->getConvertEmptyValuesToNull(), true)) {
// use nullif only for string base type
if ($columnDefinition->getColumnDefinition()->getBasetype() === BaseType::STRING) {
Expand Down Expand Up @@ -146,6 +119,13 @@ public function getInsertAllIntoTargetTableCommand(
BigqueryImportOptions $importOptions,
string $timestamp,
): string {
$columnMap = SourceDestinationColumnMap::createForTables(
$sourceTableDefinition,
$destinationTableDefinition,
$importOptions->ignoreColumns(),
SourceDestinationColumnMap::MODE_MAP_BY_NAME,
);
Comment on lines +122 to +127
Copy link
Member Author

Choose a reason for hiding this comment

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

synchronizuju logiku stím jak je to teď ve SNFLK SourceDestinationColumnMap řeší ty ignore columns


$destinationTable = sprintf(
'%s.%s',
BigqueryQuote::quoteSingleIdentifier($destinationTableDefinition->getSchemaName()),
Expand All @@ -167,7 +147,7 @@ public function getInsertAllIntoTargetTableCommand(
$columnsSetSql = [];
/** @var BigqueryColumn $columnDefinition */
foreach ($sourceTableDefinition->getColumnsDefinitions() as $columnDefinition) {
$this->assertColumnExist($destinationTableDefinition, $columnDefinition);
$columnMap->getDestination($columnDefinition);
$columnsSetSql[] = sprintf(
'%s.%s',
BigqueryQuote::quoteSingleIdentifier(self::SRC_ALIAS),
Expand All @@ -177,7 +157,7 @@ public function getInsertAllIntoTargetTableCommand(
} else {
$columnsSetSql = $this->getColumnSetSqlPartForStringTable(
$sourceTableDefinition,
$destinationTableDefinition,
$columnMap,
$importOptions,
);
}
Expand Down Expand Up @@ -285,28 +265,37 @@ public function getUpdateWithPkCommand(
): string {
$columnsSet = [];

foreach ($stagingTableDefinition->getColumnsNames() as $columnName) {
$columnMap = SourceDestinationColumnMap::createForTables(
$stagingTableDefinition,
$destinationTableDefinition,
$importOptions->ignoreColumns(),
SourceDestinationColumnMap::MODE_MAP_BY_NAME,
);

foreach ($stagingTableDefinition->getColumnsDefinitions() as $sourceColumn) {
$destinationColumn = $columnMap->getDestination($sourceColumn);

if ($importOptions->usingUserDefinedTypes()) {
$columnsSet[] = sprintf(
'%s = `src`.%s',
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($destinationColumn->getColumnName()),
BigqueryQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
);
continue;
}
// if string table convert nulls<=>''
if (in_array($columnName, $importOptions->getConvertEmptyValuesToNull(), true)) {
if (in_array($sourceColumn->getColumnName(), $importOptions->getConvertEmptyValuesToNull(), true)) {
$columnsSet[] = sprintf(
'%s = IF(`src`.%s = \'\', NULL, `src`.%s)',
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($destinationColumn->getColumnName()),
BigqueryQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
BigqueryQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
);
} else {
$columnsSet[] = sprintf(
'%s = COALESCE(`src`.%s, \'\')',
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($destinationColumn->getColumnName()),
BigqueryQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
);
}
}
Expand All @@ -321,16 +310,14 @@ public function getUpdateWithPkCommand(

$columnsComparisonSql = [];
if ($importOptions->compareAllColumnsInNativeTable()) {
$columnsComparisonSql = array_map(
static function ($columnName) {
return sprintf(
'`dest`.%s IS DISTINCT FROM `src`.%s',
BigqueryQuote::quoteSingleIdentifier($columnName),
BigqueryQuote::quoteSingleIdentifier($columnName),
);
},
$stagingTableDefinition->getColumnsNames(),
);
foreach ($stagingTableDefinition->getColumnsDefinitions() as $sourceColumn) {
$destinationColumn = $columnMap->getDestination($sourceColumn);
$columnsComparisonSql[] = sprintf(
'`dest`.%s IS DISTINCT FROM `src`.%s',
BigqueryQuote::quoteSingleIdentifier($destinationColumn->getColumnName()),
BigqueryQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
);
}
}

$dest = sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function runCopyCommand(
$source->getTableName(),
))->getColumnsDefinitions(),
destination: $destination->getColumnsDefinitions(),
ignoreSourceColumns: $importOptions->ignoreColumns(),
assertOptions: Assert::ASSERT_MINIMAL,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function load(): void
echo PHP_EOL;

$promises = [];
$promises[] = fn() => new Promise(function ($resolve) use ($bucket) {
$promises[] = fn() => new Promise(function (callable $resolve) use ($bucket): void {
$blobName = '02_tw_accounts.csv.invalid.manifest';
$res = $bucket->upload(
json_encode([
Expand All @@ -131,14 +131,16 @@ public function load(): void
'name' => $blobName,
],
);
return $resolve([$blobName, $res]);
$resolve([$blobName, $res]);
});

parallel($promises)->then(function (): void {
return;
}, function (Throwable $e): void {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
parallel($promises)->then(
function (): void {
},
function (Throwable $e): void {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
},
);

echo "GCS load complete \n";
}
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/php-storage-driver-common/proto/table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ message ImportExportShared {
CreateMode createMode = 8;

repeated string importAsNull = 9; // list of values which should be imported as null, default should be always empty string

repeated string ignoreColumnsNames = 10; // columns that are ignored during import, used to ignore _timestamp column from check when importing table from workspace
}
/**
* Common export options
Expand Down