Skip to content

Commit

Permalink
Merge pull request #1421 from keboola/jirka-ct-1854-test-alias
Browse files Browse the repository at this point in the history
CT-1854 test refresh metadata on alias
  • Loading branch information
jirkasemmler authored Nov 18, 2024
2 parents 4a6f46f + e81e17b commit 4f8357c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ Asynchronous call response that creates a new job. To see job detail use [Job De
}

### Bucket Tables Information Refresh [POST /v2/storage/branch/{branch_id}/buckets/{bucket_id}/refresh-tables-info]
Refresh tables information in bucket. For **Snowflake** backend only.
Refresh tables information in bucket. For **Snowflake** backend only. Aliases with source table in the defined bucket are also refreshed. If alias in the discussed bucket has source table in another bucket, it won't be refreshed.


+ Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Keboola\Test\Backend\ExternalBuckets;

use Keboola\StorageApi\BranchAwareClient;
use Keboola\StorageApi\Workspaces;
use Keboola\TableBackendUtils\Escaping\Snowflake\SnowflakeQuote;
use Keboola\Test\Utils\ConnectionUtils;
Expand All @@ -12,6 +13,8 @@ class SnowflakeBucketsRefreshTablesInformationTest extends BaseExternalBuckets
{
use ConnectionUtils;

const BUCKET_FINANCE = 'test-finance';
const BUCKET_ACCOUNTING = 'test-accounting';
public function testRefreshTablesInformationEndpointExists(): void
{
$bucketId = $this->initEmptyBucketWithDescription(self::STAGE_IN);
Expand Down Expand Up @@ -125,4 +128,39 @@ public function testRefreshTablesInformation(): void
),
);
}

public function testAliasesShouldNotBeRefreshedWhenSourceTableIsInAnotherBucket(): void
{
$expectedRowsForTableAndAlias = 6;

$client = $this->getBranchAwareDefaultClient('default');
foreach ([self::BUCKET_FINANCE, self::BUCKET_ACCOUNTING] as $bucketName) {
$this->dropBucketIfExists($this->_client, 'in.c-' . $bucketName);
}
$bucketIdFinance = $this->_client->createBucket(self::BUCKET_FINANCE, self::STAGE_IN);
$bucketIdAccountingWithAliasSource = $this->_client->createBucket(self::BUCKET_ACCOUNTING, self::STAGE_IN);

$tableInAccountingBucket = $this->createTableWithRandomData(
'invoices',
$expectedRowsForTableAndAlias,
3,
bucketId: $bucketIdAccountingWithAliasSource,
);

$this->createTableWithRandomData(
'invoices',
2,
3,
bucketId: $bucketIdFinance,
);

// creating alias from ACCOUNTING but in FINANCE bucket
$createdAlias = $this->_client->createAliasTable($bucketIdFinance, $tableInAccountingBucket, 'invoices_alias');
$aliasDetail = $this->_client->getTable($createdAlias);
$this->assertEquals($expectedRowsForTableAndAlias, $aliasDetail['rowsCount']);
$client->refreshTableInformationInBucket($bucketIdFinance);
$aliasDetail = $this->_client->getTable($createdAlias);
// the alias should keep the old row count
$this->assertEquals($expectedRowsForTableAndAlias, $aliasDetail['rowsCount']);
}
}
8 changes: 6 additions & 2 deletions tests/StorageApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,12 @@ protected function waitForFile($fileId, $sapiClient = null)
}
}

protected function createTableWithRandomData($tableName, $rows = 5, $columns = 10, $charsInCell = 20)
protected function createTableWithRandomData($tableName, $rows = 5, $columns = 10, $charsInCell = 20, string $bucketId = null)
{
if ($bucketId === null) {
$bucketId = $this->getTestBucketId();
}

$csvFile = $this->createTempCsv();
$header = [];
for ($i = 0; $i++ < $columns;) {
Expand All @@ -513,7 +517,7 @@ protected function createTableWithRandomData($tableName, $rows = 5, $columns = 1
}
$csvFile->writeRow($row);
}
return $this->_client->createTableAsync($this->getTestBucketId(), $tableName, $csvFile);
return $this->_client->createTableAsync($bucketId, $tableName, $csvFile);
}

protected function createTempCsv(): CsvFile
Expand Down

0 comments on commit 4f8357c

Please sign in to comment.