Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Dialect Function Translation Improvements #3454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function meta::external::store::relational::sqlDialectTranslation::functionRegis
(
parameterTypes = [AbstractNumericSqlType, AbstractNumericSqlType],
returnType = AbstractPrecisionScaleSqlType,
documentation = 'Returns the logarithm of a number (1st arg) with specified base (2nd arg).'
documentation = 'Returns the logarithm of a number (2nd arg) with specified base (1st arg).'
)
],
tests = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function meta::external::store::relational::sqlDialectTranslation::functionRegis
variations = [
^SqlFunctionVariation
(
parameterTypes = [AbstractStringSqlType, AbstractNumericSqlType],
parameterTypes = [AbstractStringSqlType, AbstractIntegerSqlType],
returnType = AbstractStringSqlType,
documentation = 'Left pads the string (1st arg) with spaces till the specified length (2nd arg).'
),
^SqlFunctionVariation
(
parameterTypes = [AbstractStringSqlType, AbstractNumericSqlType, AbstractStringSqlType],
parameterTypes = [AbstractStringSqlType, AbstractIntegerSqlType, AbstractStringSqlType],
returnType = AbstractStringSqlType,
documentation = 'Left pads the string (1st arg) with another string (3rd arg) till the specified length (2nd arg).'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function meta::external::store::relational::sqlDialectTranslation::functionRegis
variations = [
^SqlFunctionVariation
(
parameterTypes = [AbstractStringSqlType, AbstractNumericSqlType],
parameterTypes = [AbstractStringSqlType, AbstractIntegerSqlType],
returnType = AbstractStringSqlType,
documentation = 'Right-pads the string (1st arg) with spaces, till the specified length (2nd arg).'
),
^SqlFunctionVariation
(
parameterTypes = [AbstractStringSqlType, AbstractNumericSqlType, AbstractStringSqlType],
parameterTypes = [AbstractStringSqlType, AbstractIntegerSqlType, AbstractStringSqlType],
returnType = AbstractStringSqlType,
documentation = 'Right-pads the string (1st arg) with another string (3rd arg), till the specified length (2nd arg).'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTy

// ---------------------- Boolean ----------------------------------------------

Class <<typemodifiers.abstract>> meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::BooleanSqlType extends SqlType {}
Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::BooleanSqlType extends SqlType {}

// -----------------------------------------------------------------------------

// ---------------------- String ----------------------------------------------

Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::AbstractStringSqlType extends SqlType {}
Class <<typemodifiers.abstract>> meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::AbstractStringSqlType extends SqlType {}
Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::CharSqlType extends AbstractStringSqlType {}
Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::VarcharSqlType extends AbstractStringSqlType {}

// -----------------------------------------------------------------------------

// ---------------------- Date & Time ----------------------------------------------

Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::AbstractTemporalSqlType extends SqlType {}
Class <<typemodifiers.abstract>> meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::AbstractTemporalSqlType extends SqlType {}
Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::DateSqlType extends AbstractTemporalSqlType {}
Class meta::external::store::relational::sqlDialectTranslation::sqlTyping::sqlTypes::TimestampSqlType extends AbstractTemporalSqlType {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,44 @@ function meta::external::store::relational::sqlDialectTranslation::sqlTyping::ty

function <<access.private>> meta::external::store::relational::sqlDialectTranslation::sqlTyping::typeInference::typedCast(c: Cast[1]): TypedSqlExpression[1]
{
let targetType = $c.type.name;
let targetType = $c.type.name->toLower();
let sqlTypeMap = [

// Integer types
pair('int2', SmallIntSqlType),
pair('smallint', SmallIntSqlType),

pair('int', IntegerSqlType),
pair('int4', IntegerSqlType),
pair('integer', IntegerSqlType),
pair('long', BigIntSqlType),

pair('int8', BigIntSqlType),
pair('bigint', BigIntSqlType),
pair('double', DoubleSqlType),

// Decimal types
pair('numeric', NumericSqlType),
pair('decimal', DecimalSqlType),
pair('float', FloatSqlType),
pair('float4', FloatSqlType),
pair('real', RealSqlType),
pair('double precision', DoubleSqlType),
pair('float8', DoubleSqlType),

// Boolean types
pair('boolean', BooleanSqlType),
pair('string', VarcharSqlType),
pair('bool', BooleanSqlType),

// String types
pair('varchar', VarcharSqlType),
pair('character varying', VarcharSqlType),

pair('char', CharSqlType),
pair('character', CharSqlType),

// Temporal types
pair('date', DateSqlType),
pair('timestamp', TimestampSqlType)

// TODO: More types
]->newMap();
$c->typedExpression(TypedCastExpression, $sqlTypeMap->get($targetType->toLower())->toOne());
Expand Down
Loading