Skip to content

Commit acc3af7

Browse files
committed
use keboola/db-adapter-snowflake
1 parent cce5068 commit acc3af7

32 files changed

Lines changed: 306 additions & 214 deletions

composer.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{
22
"name": "keboola/db-import-export",
33
"description": "Package allows to import files to Snowflake from multiple cloud storages",
4+
"repositories": [
5+
{
6+
"type": "git",
7+
"url": "https://github.com/keboola/db-adapter-snowflake.git"
8+
}
9+
],
410
"require": {
511
"php": "^7.3",
12+
"keboola/csv": "dev-zajca-csv-options",
13+
"keboola/db-adapter-snowflake": "dev-tf-init-db-snowflake",
614
"keboola/php-component": "^7.0.1",
7-
"keboola/php-csv-db-import": "^5.0",
8-
"microsoft/azure-storage-blob": "^1.4"
15+
"microsoft/azure-storage-blob": "^1.4",
16+
"symfony/stopwatch": "^4.3"
917
},
1018
"require-dev": {
1119
"jakub-onderka/php-parallel-lint": "^1.0",
@@ -36,7 +44,6 @@
3644
"@tests-unit",
3745
"@tests-functional"
3846
],
39-
4047
"phpstan": "phpstan analyse ./src ./tests --level=max --no-progress -c phpstan.neon",
4148
"phpcs": "phpcs -n --ignore=vendor --extensions=php .",
4249
"phpcbf": "phpcbf -n --ignore=vendor --extensions=php .",
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\Db\ImportExport\Backend\Exception;
6+
7+
use Keboola\SnowflakeDbAdapter\Exception\ExceptionInterface;
8+
9+
class ColumnsCountNotMatchException extends \Exception implements ExceptionInterface
10+
{
11+
}
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\Db\ImportExport\Backend\Exception;
6+
7+
use Keboola\SnowflakeDbAdapter\Exception\ExceptionInterface;
8+
9+
class InvalidSourceDataException extends \Exception implements ExceptionInterface
10+
{
11+
}
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\Db\ImportExport\Backend\Exception;
6+
7+
use Keboola\SnowflakeDbAdapter\Exception\ExceptionInterface;
8+
9+
class MandatoryFileNotFoundException extends \Exception implements ExceptionInterface
10+
{
11+
}
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\Db\ImportExport\Backend\Exception;
6+
7+
use Keboola\SnowflakeDbAdapter\Exception\ExceptionInterface;
8+
9+
class NoColumnsFoundException extends \Exception implements ExceptionInterface
10+
{
11+
}

src/Backend/ImportResult.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\Db\ImportExport\Backend;
6+
7+
class ImportResult
8+
{
9+
/** @var array */
10+
private $results;
11+
12+
public function __construct(array $results)
13+
{
14+
$this->results = $results;
15+
}
16+
17+
public function getImportedColumns(): array
18+
{
19+
return (array) $this->getKeyValue('importedColumns', []);
20+
}
21+
22+
public function getImportedRowsCount(): int
23+
{
24+
return (int) $this->getKeyValue('importedRowsCount');
25+
}
26+
27+
public function getTimers(): array
28+
{
29+
return (array) $this->getKeyValue('timers', []);
30+
}
31+
32+
public function getWarnings(): array
33+
{
34+
return (array) $this->getKeyValue('warnings', []);
35+
}
36+
37+
/**
38+
* @param string $keyName
39+
* @param mixed|null $default
40+
* @return mixed|null
41+
*/
42+
public function getKeyValue(string $keyName, $default = null)
43+
{
44+
return isset($this->results[$keyName]) ? $this->results[$keyName] : $default;
45+
}
46+
}

src/Backend/ImportState.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Keboola\Db\ImportExport\Backend;
66

7-
use Keboola\Db\Import\Result;
8-
use Tracy\Debugger;
7+
use Symfony\Component\Stopwatch\Stopwatch;
98

109
class ImportState
1110
{
@@ -24,19 +23,25 @@ class ImportState
2423
/** @var string */
2524
private $stagingTableName = '';
2625

26+
/**
27+
* @var Stopwatch
28+
*/
29+
private $stopwatch;
30+
2731
public function __construct(string $stagingTableName)
2832
{
2933
$this->stagingTableName = $stagingTableName;
34+
$this->stopwatch = new Stopwatch();
3035
}
3136

3237
public function addImportedRowsCount(int $count): void
3338
{
3439
$this->importedRowsCount += $count;
3540
}
3641

37-
public function getResult(): Result
42+
public function getResult(): ImportResult
3843
{
39-
return new Result([
44+
return new ImportResult([
4045
'warnings' => $this->warnings,
4146
'timers' => array_values($this->timers), // convert to indexed array
4247
'importedRowsCount' => $this->importedRowsCount,
@@ -56,7 +61,7 @@ public function setImportedColumns(array $importedColumns): void
5661

5762
public function startTimer(string $timerName): void
5863
{
59-
Debugger::timer($timerName);
64+
$this->stopwatch->start($timerName);
6065
$this->timers[$timerName] = [
6166
'name' => $timerName,
6267
'durationSeconds' => null,
@@ -65,6 +70,7 @@ public function startTimer(string $timerName): void
6570

6671
public function stopTimer(string $timerName): void
6772
{
68-
$this->timers[$timerName]['durationSeconds'] = Debugger::timer($timerName);
73+
$miliseconds = $this->stopwatch->stop($timerName)->getDuration();
74+
$this->timers[$timerName]['durationSeconds'] = $miliseconds / 1000;
6975
}
7076
}

src/Backend/ImporterInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Keboola\Db\ImportExport\Backend;
66

7-
use Keboola\Db\Import\Result;
87
use Keboola\Db\ImportExport\ImportOptions;
98
use Keboola\Db\ImportExport\Storage;
109

@@ -16,5 +15,5 @@ public function importTable(
1615
Storage\SourceInterface $source,
1716
Storage\DestinationInterface $destination,
1817
ImportOptions $options
19-
): Result;
18+
): ImportResult;
2019
}

src/Backend/Snowflake/Exporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Keboola\Db\ImportExport\Backend\Snowflake;
66

7-
use Keboola\Db\Import\Snowflake\Connection;
87
use Keboola\Db\ImportExport\Backend\ExporterInterface;
98
use Keboola\Db\ImportExport\ExportOptions;
109
use Keboola\Db\ImportExport\Storage;
10+
use Keboola\SnowflakeDbAdapter\Connection;
1111

1212
class Exporter implements ExporterInterface
1313
{

src/Backend/Snowflake/Helper/ColumnsHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Keboola\Db\ImportExport\Backend\Snowflake\Helper;
66

7-
use Keboola\Db\ImportExport\Backend\Snowflake\Helper\QuoteHelper;
7+
use Keboola\SnowflakeDbAdapter\QueryBuilder;
88

99
final class ColumnsHelper
1010
{
@@ -17,7 +17,7 @@ public static function getColumnsString(
1717
$tableAlias
1818
) {
1919
$alias = $tableAlias === null ? '' : $tableAlias . '.';
20-
return $alias . QuoteHelper::quoteIdentifier($columns);
20+
return $alias . QueryBuilder::quoteIdentifier($columns);
2121
}, $columns));
2222
}
2323
}

0 commit comments

Comments
 (0)