Skip to content

Commit

Permalink
Merge pull request #122 from keboola/erik-metadata-backend
Browse files Browse the repository at this point in the history
[php-datatypes] METADATA_BACKEND const for Datatype Definitions
  • Loading branch information
ErikZigo authored Dec 29, 2023
2 parents 8360533 + f1efb2c commit f111335
Show file tree
Hide file tree
Showing 363 changed files with 3,958 additions and 3,898 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"symfony/process": "^4.4|^5.0|^6.0"
},
"require-dev": {
"keboola/coding-standard": "^14",
"keboola/coding-standard": "^15",
"keboola/phpunit-retry-annotations": "^0.3.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/php-datatypes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"squizlabs/php_codesniffer": "^3",
"phpstan/phpstan": "^1.4",
"php-parallel-lint/php-parallel-lint": "^1.3",
"keboola/coding-standard": "^14",
"keboola/coding-standard": "^15",
"phpstan/phpdoc-parser": "^1.6"
},
"autoload": {
Expand Down
6 changes: 4 additions & 2 deletions packages/php-datatypes/src/Definition/Bigquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Bigquery extends Common

public const MAX_LENGTH = 9223372036854775807;

public const METADATA_BACKEND = 'bigquery';

/** @phpstan-var BigqueryTableFieldSchema|null */
private ?array $fieldAsArray = null;

Expand Down Expand Up @@ -319,7 +321,7 @@ private function validateLength(string $type, $length = null): void
protected function validateBigqueryNumericLength(
$length,
int $firstMax,
int $secondMax
int $secondMax,
): bool {
if ($this->isEmpty($length)) {
return true;
Expand All @@ -340,7 +342,7 @@ protected function validateBigqueryNumericLength(
protected function validateBigNumericLength(
$length,
int $firstMax,
int $secondMax
int $secondMax,
): bool {
if ($this->isEmpty($length)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/php-datatypes/src/Definition/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function validateNumericLength(
$length,
int $firstMax,
int $secondMax,
bool $firstMustBeBigger = true
bool $firstMustBeBigger = true,
): bool {
if ($this->isEmpty($length)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/php-datatypes/src/Definition/Oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function getTypeByBasetype(string $basetype): string
BaseType::NUMERIC, BaseType::FLOAT, BaseType::BOOLEAN, BaseType::INTEGER => self::TYPE_NUMBER,
BaseType::TIMESTAMP, BaseType::DATE => self::TYPE_DATE,
default => throw new InvalidTypeException(
sprintf('No Oracle type mapped for base type "%s"', $basetype)
sprintf('No Oracle type mapped for base type "%s"', $basetype),
),
};
}
Expand Down
2 changes: 2 additions & 0 deletions packages/php-datatypes/src/Definition/Redshift.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Redshift extends Common
'TIMESTAMPTZ', 'TIMESTAMP WITH TIME ZONE',
];

public const METADATA_BACKEND = 'redshift';

protected ?string $compression = null;

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/php-datatypes/src/Definition/Teradata.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ class Teradata extends Common
self::TYPE_NUMBER => '-128,-128',
];

public const METADATA_BACKEND = 'teradata';

private bool $isLatin = false;

// depends on Char Type column in HELP TABLE column
Expand Down Expand Up @@ -592,7 +594,7 @@ private function validateLength(string $type, $length = null): void
'K' => $isLatin ? 2_047_937 : 1_023_968,
'M' => $isLatin ? 1999 : 999,
'G' => $isLatin ? 1 : 0,
]
],
);
break;
case self::TYPE_BLOB:
Expand All @@ -604,7 +606,7 @@ private function validateLength(string $type, $length = null): void
'K' => 2_047_937,
'M' => 1999,
'G' => 1,
]
],
);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/php-datatypes/tests/CommonDatatypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function testConstructor(): void

$datatype = $this->getMockForAbstractClass(
Common::class,
['VARCHAR', ['length' => '50', 'nullable' => false, 'default' => '']]
['VARCHAR', ['length' => '50', 'nullable' => false, 'default' => '']],
);
$this->assertTrue($datatype->getLength() === '50');
$this->assertTrue(!$datatype->isNullable());
$this->assertTrue($datatype->getDefault() === '');

$datatype = $this->getMockForAbstractClass(
Common::class,
['VARCHAR', ['length' => 50, 'nullable' => false, 'default' => 123]]
['VARCHAR', ['length' => 50, 'nullable' => false, 'default' => 123]],
);
$this->assertTrue($datatype->getLength() === '50');
$this->assertTrue(!$datatype->isNullable());
Expand Down
6 changes: 3 additions & 3 deletions packages/php-datatypes/tests/ExasolDatatypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public function testDefaultTypeForNumberBasedOnLength(): void
{
self::assertSame(
BaseType::NUMERIC,
(new Exasol('NUMBER', ['length' => '10,5']))->getBasetype()
(new Exasol('NUMBER', ['length' => '10,5']))->getBasetype(),
);
self::assertSame(
BaseType::FLOAT,
(new Exasol('NUMBER', ['length' => null]))->getBasetype()
(new Exasol('NUMBER', ['length' => null]))->getBasetype(),
);
}

Expand Down Expand Up @@ -202,7 +202,7 @@ public function expectedSqlDefinitions(): array
['length' => '20,20', 'default' => 10, 'nullable' => true],
'NUMBER (20,20) DEFAULT 10',
],
]
],
);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/php-datatypes/tests/RedshiftDatatypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ public function testToArray(): void
$datatype = new Redshift('VARCHAR');
$this->assertEquals(
['type' => 'VARCHAR', 'length' => null, 'nullable' => true, 'compression' => null],
$datatype->toArray()
$datatype->toArray(),
);

$datatype = new Redshift('VARCHAR', ['length' => '50', 'nullable' => false, 'compression' => 'ZSTD']);
$this->assertEquals(
['type' => 'VARCHAR', 'length' => '50', 'nullable' => false, 'compression' => 'ZSTD'],
$datatype->toArray()
$datatype->toArray(),
);
}

public function testToMetadata(): void
{
$datatype = new Redshift(
'VARCHAR',
['length' => '50', 'nullable' => false, 'default' => '', 'compression' => 'ZSTD']
['length' => '50', 'nullable' => false, 'default' => '', 'compression' => 'ZSTD'],
);

$md = $datatype->toMetadata();
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testBasetypes(): void
{
$types = array_merge(
Redshift::TYPES,
array_map(fn($v) => strtolower($v), Redshift::TYPES)
array_map(fn($v) => strtolower($v), Redshift::TYPES),
);
foreach ($types as $type) {
$basetype = (new Redshift($type))->getBasetype();
Expand Down
2 changes: 1 addition & 1 deletion packages/php-db-import-export/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"symfony/process": "^4.4|^5.0|^6.0"
},
"require-dev": {
"keboola/coding-standard": "^14",
"keboola/coding-standard": "^15",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AzCli
public function __construct(
string $azureServicePrincipalTenant,
string $azureServicePrincipal,
string $azureServicePrincipalPassword
string $azureServicePrincipalPassword,
) {
$this->azureServicePrincipalTenant = $azureServicePrincipalTenant;
$this->azureServicePrincipal = $azureServicePrincipal;
Expand All @@ -28,7 +28,7 @@ public function __construct(
public function runAuthorizedSingleLineOutputCmd(string $cmd): string
{
$out = $this->runAuthorizedCmd(
$cmd
$cmd,
);
return explode(PHP_EOL, $out)[0];
}
Expand Down
6 changes: 3 additions & 3 deletions packages/php-db-import-export/provisioning/src/BaseCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ protected function configure(): void
->addOption(
self::OPTION_AZURE_SERVICE_PRINCIPAL_TENANT,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);

$this
->addOption(
self::OPTION_AZURE_SERVICE_PRINCIPAL,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);

$this
->addOption(
self::OPTION_AZURE_SERVICE_PRINCIPAL_PASSWORD,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
}

Expand Down
24 changes: 10 additions & 14 deletions packages/php-db-import-export/provisioning/src/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,37 @@ protected function configure(): void
->addOption(
self::OPTION_AZURE_RESOURCE_GROUP,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
$this
->addOption(
self::OPTION_SYNAPSE_DW_SERVER_NAME,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
$this
->addOption(
self::OPTION_SYNAPSE_SQL_SERVER_NAME,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
$this
->addOption(
self::OPTION_FILE_STORAGE_RESOURCE_ID,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
$this
->addOption(
self::OPTION_SYNAPSE_SERVICE_PRINCIPAL_OBJECT_ID,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
$this
->addOption(
self::OPTION_STORAGE_ACCOUNT_NAME,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
parent::configure();
}
Expand Down Expand Up @@ -86,8 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
--assignee $servicePrincipalObjetId \
--role "Storage Blob Data Contributor" \
--scope $fileStorageResourceId
EOT
);
EOT,);
$output->writeln([
'Managed identity role removed',
]);
Expand All @@ -100,8 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
--resource-group $resourceGroup \
--name $synapseDwServerName \
--server $synapseSqlServerName
EOT
);
EOT,);
$output->writeln([
'Synapse pool removed',
]);
Expand All @@ -113,8 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
az sql server delete -y \
--resource-group $resourceGroup \
--name $synapseSqlServerName
EOT
);
EOT,);
$output->writeln([
'Synapse logical sql server removed',
]);
Expand All @@ -126,8 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
az storage account delete -y \
--resource-group $resourceGroup \
--name $storageAccountName
EOT
);
EOT,);
$output->writeln([
'Blob storage account removed',
]);
Expand Down
22 changes: 8 additions & 14 deletions packages/php-db-import-export/provisioning/src/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ protected function configure(): void
->addOption(
self::OPTION_SERVER_NAME,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
$this
->addOption(
self::OPTION_AZURE_RESOURCE_GROUP,
null,
InputOption::VALUE_REQUIRED
InputOption::VALUE_REQUIRED,
);
parent::configure();
}
Expand Down Expand Up @@ -60,8 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
--output json \
--parameters \
suffix=$suffix
EOT
);
EOT,);
$outBlobDeploy = $this->getDeploymentResult($outBlobDeploy);
$storageAccountName = $outBlobDeploy['properties']['outputs']['storageAccountName']['value'];
$storageAccountKey = $outBlobDeploy['properties']['outputs']['storageAccountKey']['value'];
Expand Down Expand Up @@ -89,8 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
warehouseName=$serverName \
suffix=$suffix \
warehouseCapacity=900
EOT
);
EOT,);

$outSynapseDeploy = $this->getDeploymentResult($outSynapseDeploy);
$synapseSqlServerName = $outSynapseDeploy['properties']['outputs']['sqlServerName']['value'];
Expand Down Expand Up @@ -123,8 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
--name all \
--start-ip-address 0.0.0.0 \
--end-ip-address 255.255.255.255
EOT
);
EOT,);

$output->writeln([
'Firewall rule set done',
Expand All @@ -136,8 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
--display-name $synapseSqlServerName \
--query "[].objectId" \
--output tsv
EOT
);
EOT,);

$output->writeln([
'SYNAPSE_SERVICE_PRINCIPAL_OBJECT_ID: ' . $principalObjectId,
Expand All @@ -150,8 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
-n $storageAccountName \
--query "id" \
--output tsv
EOT
);
EOT,);

$output->writeln([
'FILE_STORAGE_RESOURCE_ID: ' . $fileStorageResourceId,
Expand All @@ -162,8 +157,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
--assignee $principalObjectId \
--role "Storage Blob Data Contributor" \
--scope $fileStorageResourceId
EOT
);
EOT,);

$output->writeln([
'Managed identity role created',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function addEnv(string $name, string $value): void
$fs->appendToFile($this->envFile, sprintf(
'echo "##vso[task.setvariable variable=%s]%s"' . PHP_EOL,
$name,
$value
$value,
));
}
}
Loading

0 comments on commit f111335

Please sign in to comment.