CT-1128 SNFLK autocast types when using string stage table#90
Conversation
| public function getType(): string; | ||
|
|
||
| public function getLength(): ?string; | ||
|
|
||
| public function isNullable(): bool; | ||
|
|
||
| public function getDefault(): ?string; | ||
|
|
There was a problem hiding this comment.
nechápu proč to neni v tom interface
| bool $nullManipulation = self::NULL_MANIPULATION_ENABLED, | ||
| array $ignoreColumns = [] | ||
| array $ignoreColumns = [], | ||
| array $autoCastTypes = [], |
There was a problem hiding this comment.
to co sa má castovat sem dal jako option ať to jde nastavit z connection
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
toto je to co bych tam chtel https://github.com/keboola/storage-backend/pull/90/files#r1331117689
There was a problem hiding this comment.
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é.
| $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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
tady to mapování source->destination sloupců sem potřeboval dostat někam ven.
jirkasemmler
left a comment
There was a problem hiding this comment.
v zasade ok, mam par doplnujicich dotazu a prani
| bool $nullManipulation = self::NULL_MANIPULATION_ENABLED, | ||
| array $ignoreColumns = [] | ||
| array $ignoreColumns = [], | ||
| array $autoCastTypes = [], |
There was a problem hiding this comment.
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 = [], |
There was a problem hiding this comment.
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 = [], |
There was a problem hiding this comment.
toto je to co bych tam chtel https://github.com/keboola/storage-backend/pull/90/files#r1331117689
| $useAutoCast = in_array($type, $importOptions->autoCastTypes(), true); | ||
| $isSameType = $type === $sourceColumn->getColumnDefinition()->getType(); | ||
| if ($useAutoCast && !$isSameType) { | ||
| if ($type === Snowflake::TYPE_OBJECT) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
ta metoda je takto nadesignovana, ale ten ty continue misto trochu lepe organizovaneho if else mi prijdou strasne neprehledne
There was a problem hiding this comment.
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: [], |
| /** | ||
| * 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 |
There was a problem hiding this comment.
we ignore in this test... ale takze co se stane, kdyz to nekdo pouzije?
There was a problem hiding this comment.
Hehe upravil sem sem on ten GEOMETRY a GEOGRAPHY funguje automaticky :) Takže sem ho přidal do testu.
|
Přihodil sem ještě error handling |
JIRA: CT-1128