Skip to content

Comments

CT-1128 SNFLK autocast types when using string stage table#90

Merged
zajca merged 10 commits intomainfrom
zajca-ct-1116
Sep 25, 2023
Merged

CT-1128 SNFLK autocast types when using string stage table#90
zajca merged 10 commits intomainfrom
zajca-ct-1116

Conversation

@zajca
Copy link
Member

@zajca zajca commented Sep 19, 2023

JIRA: CT-1128

@zajca zajca marked this pull request as draft September 19, 2023 13:45
Comment on lines +18 to +25
public function getType(): string;

public function getLength(): ?string;

public function isNullable(): bool;

public function getDefault(): ?string;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nechápu proč to neni v tom interface

bool $nullManipulation = self::NULL_MANIPULATION_ENABLED,
array $ignoreColumns = []
array $ignoreColumns = [],
array $autoCastTypes = [],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to co sa má castovat sem dal jako option ať to jde nastavit z connection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a seznam typu na autoCast budeme drzet v datatypes (jako se to planuje tady Package/StorageBackend/src/LegacyBackendConfig/SnowflakeConfig.php ) nebo to bude drzet connnection tady Package/StorageBackend/src/LegacyBackendConfig/SnowflakeConfig.php ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus mohla by ta option dostat kus komentare? co to dela? to je strasnej pain tady tech options, ze pak clovek musi rozmotavat kde se to pouziva a jake to ma dopady

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@zajca zajca Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smazal sem to, upravil sem test, vlatně je to potřeba po dalším testování jen pro 3 typy:

Snowflake::TYPE_VARIANT,
Snowflake::TYPE_OBJECT,
Snowflake::TYPE_ARRAY,

ostatní SNFLK nějak sám přecastuje z toho stringu.
Původně sem nad tím přemýšlal tak, že to půjde nastavit v connection a nebude potřeba šahat sem, ale vlastně je to blbost a chceš to mět tady odzkůšané.

Comment on lines 193 to 217
$destinationColumn = $columnMap->getDestination($sourceColumn);
$type = $destinationColumn->getColumnDefinition()->getType();
$useAutoCast = in_array($type, $importOptions->autoCastTypes(), true);
$isSameType = $type === $sourceColumn->getColumnDefinition()->getType();
if ($useAutoCast && !$isSameType) {
if ($type === Snowflake::TYPE_OBJECT) {
// object can't be casted from string but can be casted from variant
$columnsSetSql[] = sprintf(
'CAST(TO_VARIANT(%s) AS %s) AS %s',
SnowflakeQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
$destinationColumn->getColumnDefinition()->getSQLDefinition(),
SnowflakeQuote::quoteSingleIdentifier($destinationColumn->getColumnName())
);
continue;
}
$columnsSetSql[] = sprintf(
'CAST(%s AS %s) AS %s',
SnowflakeQuote::quoteSingleIdentifier($sourceColumn->getColumnName()),
$destinationColumn->getColumnDefinition()->getSQLDefinition(),
SnowflakeQuote::quoteSingleIdentifier($destinationColumn->getColumnName())
);
continue;
}
$columnsSetSql[] = SnowflakeQuote::quoteSingleIdentifier($sourceColumn->getColumnName());
continue;
Copy link
Member Author

@zajca zajca Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null manipulation flag je pro load/unload do WS pro netypové tabulky když chceme konvertovat '' na null hodnoty.

Pro load z CSV ho je ten flag false a to je kdy to potřebujeme konvertovat ze string stage tabulek do typovaných tabulek.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stejné věc je potřeba pro vkládání nových hodnot a pro update stávajících hodnot.

/**
* Class will create map of table column based on columns order
*/
final class SourceDestinationColumnMap
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady to mapování source->destination sloupců sem potřeboval dostat někam ven.

@zajca zajca marked this pull request as ready for review September 20, 2023 10:04
@zajca zajca requested review from a team and jirkasemmler and removed request for a team September 20, 2023 10:04
@zajca zajca changed the title CT-1116 SNFLK autocast types when using string stage table CT-1128 SNFLK autocast types when using string stage table Sep 21, 2023
Copy link
Contributor

@jirkasemmler jirkasemmler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v zasade ok, mam par doplnujicich dotazu a prani

bool $nullManipulation = self::NULL_MANIPULATION_ENABLED,
array $ignoreColumns = []
array $ignoreColumns = [],
array $autoCastTypes = [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a seznam typu na autoCast budeme drzet v datatypes (jako se to planuje tady Package/StorageBackend/src/LegacyBackendConfig/SnowflakeConfig.php ) nebo to bude drzet connnection tady Package/StorageBackend/src/LegacyBackendConfig/SnowflakeConfig.php ?

bool $nullManipulation = self::NULL_MANIPULATION_ENABLED,
array $ignoreColumns = []
array $ignoreColumns = [],
array $autoCastTypes = [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus mohla by ta option dostat kus komentare? co to dela? to je strasnej pain tady tech options, ze pak clovek musi rozmotavat kde se to pouziva a jake to ma dopady

bool $nullManipulation = self::NULL_MANIPULATION_ENABLED,
array $ignoreColumns = []
array $ignoreColumns = [],
array $autoCastTypes = [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$useAutoCast = in_array($type, $importOptions->autoCastTypes(), true);
$isSameType = $type === $sourceColumn->getColumnDefinition()->getType();
if ($useAutoCast && !$isSameType) {
if ($type === Snowflake::TYPE_OBJECT) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady ocekavame to ze pro dalsi edgecasy co prijdou, tak se to bude vetvit, ze? Nechces to nekam vycuknout? kdyz to nechame takto, tak s dalsim typem prijde copypaste stejneho ifu. Ale asi je to pre-mature... necham na tobe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prakjticky sem teď přidal test pro GEOMETRY a GEOGRAPHY víc takových typů tam není takže to dost pravděpodobně potřeba vůbec nebude pro nic dalšího.

$destinationColumn->getColumnDefinition()->getSQLDefinition(),
SnowflakeQuote::quoteSingleIdentifier($destinationColumn->getColumnName())
);
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ta metoda je takto nadesignovana, ale ten ty continue misto trochu lepe organizovaneho if else mi prijdou strasne neprehledne

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if else by byl hrozný hell, možeš to zkusit jak by to vypadalo :) Možná match(true) by to trochu pošéfoval, ale takto jdeš po těch podmínkách a máš early return přes continue. Když je to "flat" přes else if tak bude strašně komplikované ty elseif poskládat správně pod sebe.

false,
$useTimeStamp,
$skipLines
convertEmptyValuesToNull: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

/**
* Test is testing loading of semi-structured data into typed table.
*
* We ignore here GEOGRAPHY and GEOMETRY as they act differently when casting from string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we ignore in this test... ale takze co se stane, kdyz to nekdo pouzije?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe upravil sem sem on ten GEOMETRY a GEOGRAPHY funguje automaticky :) Takže sem ho přidal do testu.

@zajca zajca requested a review from jirkasemmler September 22, 2023 08:55
@zajca
Copy link
Member Author

zajca commented Sep 22, 2023

Přihodil sem ještě error handling

@zajca zajca merged commit 8d80886 into main Sep 25, 2023
@zajca zajca deleted the zajca-ct-1116 branch September 25, 2023 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants