Skip to content

Commit

Permalink
Revert useless diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfejfar committed Nov 8, 2018
1 parent a0cbdca commit 8c4b2c0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 70 deletions.
117 changes: 51 additions & 66 deletions src/Keboola/DbExtractor/Extractor/Snowflake.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ public function testConnection(): void
}

try {
$this->db->query(
sprintf(
'USE WAREHOUSE %s;',
$this->db->quoteIdentifier($warehouse)
)
);
$this->db->query(sprintf(
'USE WAREHOUSE %s;',
$this->db->quoteIdentifier($warehouse)
));
} catch (\Throwable $e) {
if (preg_match('/Object does not exist/ui', $e->getMessage())) {
throw new UserException(sprintf('Invalid warehouse "%s" specified', $warehouse));
Expand Down Expand Up @@ -300,24 +298,22 @@ private function executeCopyCommand(string $copyCommand, int $maxTries = 5): arr
/** @var \Exception $lastException */
$lastException = null;
try {
$ret = $proxy->call(
function () use ($copyCommand, &$counter, &$lastException) {
if ($counter > 0) {
$this->logger->info(sprintf('%s. Retrying... [%dx]', $lastException->getMessage(), $counter));
}
try {
return $this->db->fetchAll($copyCommand);
} catch (\Throwable $e) {
$lastException = new UserException(
sprintf("Copy Command failed: %s", $e->getMessage()),
0,
$e
);
$counter++;
throw $e;
}
$ret = $proxy->call(function () use ($copyCommand, &$counter, &$lastException) {
if ($counter > 0) {
$this->logger->info(sprintf('%s. Retrying... [%dx]', $lastException->getMessage(), $counter));
}
);
try {
return $this->db->fetchAll($copyCommand);
} catch (\Throwable $e) {
$lastException = new UserException(
sprintf("Copy Command failed: %s", $e->getMessage()),
0,
$e
);
$counter++;
throw $e;
}
});
} catch (\Throwable $e) {
if ($lastException !== null) {
throw $lastException;
Expand Down Expand Up @@ -438,15 +434,12 @@ public function getTables(?array $tables = null): array
"SELECT * FROM information_schema.columns
WHERE TABLE_NAME IN (%s)
ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION",
implode(
', ',
array_map(
function ($tableName): string {
return $this->quote($tableName);
},
$tableNameArray
)
)
implode(', ', array_map(
function ($tableName): string {
return $this->quote($tableName);
},
$tableNameArray
))
);

$columns = $this->db->fetchAll($sql);
Expand Down Expand Up @@ -490,15 +483,12 @@ public function simpleQuery(array $table, array $columns = array()): string
if (count($columns) > 0) {
return sprintf(
"SELECT %s FROM %s.%s",
implode(
', ',
array_map(
function ($column): string {
return $this->db->quoteIdentifier($column);
},
$columns
)
),
implode(', ', array_map(
function ($column): string {
return $this->db->quoteIdentifier($column);
},
$columns
)),
$this->db->quoteIdentifier($table['schema']),
$this->db->quoteIdentifier($table['tableName'])
);
Expand All @@ -515,22 +505,19 @@ private function simpleQueryWithCasting(array $table, array $columnInfo) : strin
{
return sprintf(
"SELECT %s FROM %s.%s",
implode(
', ',
array_map(
function ($column): string {
if (in_array($column['type'], self::SEMI_STRUCTURED_TYPES)) {
return sprintf(
'CAST(%s AS TEXT) AS %s',
$this->db->quoteIdentifier($column['name']),
$this->db->quoteIdentifier($column['name'])
);
}
return $this->db->quoteIdentifier($column['name']);
},
$columnInfo
)
),
implode(', ', array_map(
function ($column): string {
if (in_array($column['type'], self::SEMI_STRUCTURED_TYPES)) {
return sprintf(
'CAST(%s AS TEXT) AS %s',
$this->db->quoteIdentifier($column['name']),
$this->db->quoteIdentifier($column['name'])
);
}
return $this->db->quoteIdentifier($column['name']);
},
$columnInfo
)),
$this->db->quoteIdentifier($table['schema']),
$this->db->quoteIdentifier($table['tableName'])
);
Expand All @@ -557,15 +544,13 @@ function ($item): bool {

foreach ($lines as $line) {
if (!preg_match('/^downloaded$/ui', $line[2])) {
throw new \Exception(
sprintf(
"Cannot download file: %s Status: %s Size: %s Message: %s",
$line[0],
$line[2],
$line[1],
$line[3]
)
);
throw new \Exception(sprintf(
"Cannot download file: %s Status: %s Size: %s Message: %s",
$line[0],
$line[2],
$line[1],
$line[3]
));
}

$file = new \SplFileInfo($path . '/' . $line[0]);
Expand Down
6 changes: 2 additions & 4 deletions tests/AbstractSnowflakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ public function setUp(): void
sprintf("USE SCHEMA %s", $this->connection->quoteIdentifier($config['parameters']['db']['schema']))
);

$this->storageApiClient = new Client(
[
$this->storageApiClient = new Client([
'token' => getenv('STORAGE_API_TOKEN'),
]
);
]);

$this->setupTables();

Expand Down

0 comments on commit 8c4b2c0

Please sign in to comment.