Skip to content

Commit 5fc0739

Browse files
committed
test(table import): Deduplication strategy as parameter
- DMD-177
1 parent b15bdbb commit 5fc0739

4 files changed

Lines changed: 21 additions & 17 deletions

File tree

apiary.apib

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,6 +3001,11 @@ Further information can be found in the [Developers Documentation](https://devel
30013001
+ escapedBy (optional, string) - Escape character used in the CSV file. The default value is an empty value - no escape character is used. (Note: you can specify either `enclosure` or `escapedBy` parameter, not both.)
30023002
+ columns[] (optional, string) - List of columns present in the CSV file; the first line of the file will not be treated as a header!
30033003
+ withoutHeaders (optional, boolean) - The CSV file doesn't contain headers, columns are matched by their order. If this option is used, columns option is ignored.
3004+
+ deduplicationStrategy (optional, enum[string]) - (Snowflake only) Specifies how to handle duplicate rows in the imported data.
3005+
+ Members
3006+
+ upsert - Existing rows are updated with the new data, and new rows are added.
3007+
+ insert - New rows are added, and existing rows are not updated.
3008+
+ Default: upsert
30043009
30053010
+ Request (application/json)
30063011
+ Headers

src/Keboola/StorageApi/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ private function writeTableOptionsPrepare($options)
13361336
'treatValuesAsNull',
13371337
'ignoredLinesCount',
13381338
'useTimestampFromDataFile',
1339+
'deduplicationStrategy',
13391340
];
13401341

13411342
$filteredOptions = array_intersect_key($options, array_flip($allowedOptions));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\StorageApi\Options\TableImport;
6+
7+
enum DeduplicationStrategy: string
8+
{
9+
case INSERT = 'insert';
10+
case UPSERT = 'upsert';
11+
}

tests/Backend/Snowflake/TypedTableInWorkspaceTest.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Keboola\Test\Backend\Snowflake;
44

55
use Keboola\Datatype\Definition\Snowflake;
6-
use Keboola\StorageApi\ClientException;
6+
use Keboola\StorageApi\Options\TableImport\DeduplicationStrategy;
77
use Keboola\StorageApi\Workspaces;
88
use Keboola\TableBackendUtils\Column\ColumnCollection;
99
use Keboola\TableBackendUtils\Column\ColumnInterface;
@@ -109,13 +109,8 @@ public function testUnloadFromWSToTypedTable(): void
109109
$this->unloadAndAssert($workspace['id'], $tableId);
110110
}
111111

112-
public function testUnloadFromWSToTypedTableCTAS(): void
112+
public function testUnloadFromWSToTypedTableWithoutDeduplication(): void
113113
{
114-
if (!in_array('ctas-om', $this->_client->verifyToken()['owner']['features'], true)) {
115-
$this->markTestSkipped(
116-
'CTAS is not enabled for this project, skipping test.',
117-
);
118-
}
119114
// create workspace and source table in workspace
120115
$workspace = $this->initTestWorkspace();
121116

@@ -178,6 +173,7 @@ public function testUnloadFromWSToTypedTableCTAS(): void
178173
$this->_client->writeTableAsyncDirect($this->tableId, [
179174
'dataWorkspaceId' => $workspace['id'],
180175
'dataTableName' => $tableId,
176+
'deduplicationStrategy' => DeduplicationStrategy::INSERT->value,
181177
]);
182178
$eventAssertCallback = function ($events) {
183179
$this->assertCount(1, $events);
@@ -250,6 +246,7 @@ public function testUnloadFromWSToTypedTableCTAS(): void
250246
'dataWorkspaceId' => $workspace['id'],
251247
'dataTableName' => $tableId,
252248
'incremental' => true,
249+
'deduplicationStrategy' => DeduplicationStrategy::INSERT->value,
253250
]);
254251

255252
$eventAssertCallback = function ($events) {
@@ -348,16 +345,6 @@ public function testUnloadFromWSToTypedTableCTAS(): void
348345
'format' => 'json',
349346
]);
350347
self::assertEquals($expectedIncrementalLoad, $data['rows']);
351-
352-
$this->expectException(ClientException::class);
353-
// create table does not support typed tables
354-
// tables are created by runner and this is never called
355-
$this->expectExceptionMessage('Table import error: Source destination columns mismatch. "id NUMBER (38,0) NOT NULL"->"id VARCHAR NOT NULL DEFAULT \'\'');
356-
$this->_client->createTableAsyncDirect($this->getTestBucketId(self::STAGE_IN), [
357-
'name' => 'languagesNew',
358-
'dataWorkspaceId' => $workspace['id'],
359-
'dataObject' => $tableId,
360-
]);
361348
}
362349

363350
private function unloadAndAssert(int $id, string $tableId): void

0 commit comments

Comments
 (0)