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

Add to_boolean snowflake dyna function #2846

Merged
merged 2 commits into from
May 13, 2024
Merged
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 @@ -171,6 +171,7 @@ function <<access.private>> meta::relational::functions::sqlQueryToString::snowf
dynaFnToSql('parseFloat', $allStates, ^ToSql(format='cast(%s as float)')),
dynaFnToSql('parseInteger', $allStates, ^ToSql(format='cast(%s as integer)')),
dynaFnToSql('parseJson', $allStates, ^ToSql(format='parse_json(%s)')),
dynaFnToSql('parseBoolean', $allStates, ^ToSql(format='to_boolean(%s)')),
dynaFnToSql('position', $allStates, ^ToSql(format='position(%s in %s)')),
dynaFnToSql('previousDayOfWeek', $allStates, ^ToSql(format='dateadd(DAY, case when %s - DAYOFWEEK(%s) +1 >= 0 then %s - DAYOFWEEK(%s) -1 - 7 else %s - DAYOFWEEK(%s) -1 end, %s)', transform={p:String[1..2] | $p->formatMostRecentSnowflake('current_date')}, parametersWithinWhenClause = [false, false])),
dynaFnToSql('quarter', $allStates, ^ToSql(format='quarter(%s)')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,11 @@ function <<test.Test>> meta::relational::tests::mapping::function::snowflake::te
meta::relational::runtime::DatabaseType.Snowflake, meta::relational::extension::relationalExtensions());
assertEquals('select to_timestamp("root".stringDateTimeFormat,\'YYYY-MM-DDTHH:MI:SS.FF\') as "convertToDateTime" from dataTable as "root"',$s);
}

function <<test.Test>> meta::relational::tests::mapping::function::snowflake::testToBoolean():Boolean[1]
{
let s = toSQLString(|SqlFunctionDemo.all()->project([s | $s.toBoolean], ['bolValue']),
testMapping,
meta::relational::runtime::DatabaseType.Snowflake, meta::relational::extension::relationalExtensions());
assertEquals('select to_boolean(\'true\') as "bolValue" from dataTable as "root"',$s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ function <<test.Test>> meta::relational::tests::query::snowflake::testFilterBool
}


function <<test.Test>> meta::relational::tests::query::snowflake::testBooleanParsing():Boolean[1]
{
let fn = {|Person.all()->project([col(p|$p.firstName,'firstName'), col(p|'true'->parseBoolean(), 'bool')])};
let s = toSQLString($fn, simpleRelationalMapping, meta::relational::runtime::DatabaseType.Snowflake, meta::relational::extension::relationalExtensions());
assertEquals('select "root".FIRSTNAME as "firstName", to_boolean(\'true\') as "bool" from personTable as "root"',$s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8142,6 +8142,7 @@ function meta::relational::functions::pureToSqlQuery::getSupportedFunctions():Ma
^PureFunctionToRelationalFunctionPair(first=meta::pure::functions::lang::extractEnumValue_Enumeration_1__String_1__T_1_, second=meta::relational::functions::pureToSqlQuery::processEnumValue_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
^PureFunctionToRelationalFunctionPair(first=meta::pure::functions::string::parseDate_String_1__Date_1_,second=meta::relational::functions::pureToSqlQuery::processParseDate_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
^PureFunctionToRelationalFunctionPair(first=meta::pure::functions::string::parseFloat_String_1__Float_1_,second=meta::relational::functions::pureToSqlQuery::processDynaFunction_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
^PureFunctionToRelationalFunctionPair(first=meta::pure::functions::string::parseBoolean_String_1__Boolean_1_,second=meta::relational::functions::pureToSqlQuery::processDynaFunction_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
^PureFunctionToRelationalFunctionPair(first=meta::pure::functions::string::parseDecimal_String_1__Decimal_1_,second=meta::relational::functions::pureToSqlQuery::processDynaFunction_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
^PureFunctionToRelationalFunctionPair(first=meta::pure::tds::extend_TabularDataSet_1__BasicColumnSpecification_MANY__TabularDataSet_1_,second=meta::relational::functions::pureToSqlQuery::processTdsExtend_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
^PureFunctionToRelationalFunctionPair(first=meta::pure::tds::project_TabularDataSet_1__ColumnSpecification_MANY__TabularDataSet_1_,second=meta::relational::functions::pureToSqlQuery::processTdsProject_FunctionExpression_1__PropertyMapping_MANY__SelectWithCursor_1__Map_1__State_1__JoinType_1__String_1__List_1__DebugContext_1__Extension_MANY__RelationalOperationElement_1_),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ Enum meta::relational::functions::sqlQueryToString::DynaFunctionRegistry
parseFloat,
parseInteger,
parseJson,
parseBoolean,
percentile,
plus,
position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function <<test.Test>> meta::relational::tests::testSuite::ensureEveryDynaFnIsTe
meta::relational::tests::dbSpecificTests::sqlQueryTests::selectSubClauses::aggregationDynaFns
];
let testedDynaFnNames = $packagesContainingDynaFnTests.children->filter(c| $c->instanceOf(Package)).name;
let testingIgnoredDynaFnNames = ['add', 'averageRank', 'cbrt', 'case', 'convertDate', 'convertDateTime', 'convertVarchar128', 'decodeBase64', 'denseRank', 'distinct', 'divide', 'encodeBase64', 'exists', 'group', 'if', 'isAlphaNumeric', 'isDistinct', 'isNumeric', 'minus', 'not', 'objectReferenceIn', 'parseDate', 'parseDecimal', 'parseFloat', 'parseInteger', 'parseJson', 'percentile', 'plus', 'rank', 'rowNumber', 'sub', 'times', 'toOne', 'toString', 'extractFromSemiStructured', 'explodeSemiStructured'];
let testingIgnoredDynaFnNames = ['add', 'averageRank', 'cbrt', 'case', 'convertDate', 'convertDateTime', 'convertVarchar128', 'decodeBase64', 'denseRank', 'distinct', 'divide', 'encodeBase64', 'exists', 'group', 'if', 'isAlphaNumeric', 'isDistinct', 'isNumeric', 'minus', 'not', 'objectReferenceIn', 'parseDate', 'parseDecimal', 'parseFloat', 'parseInteger', 'parseBoolean','parseJson', 'percentile', 'plus', 'rank', 'rowNumber', 'sub', 'times', 'toOne', 'toString', 'extractFromSemiStructured', 'explodeSemiStructured'];
let incorrectlyMarkedDynaFnNames = $testingIgnoredDynaFnNames->filter(n| $n->in($testedDynaFnNames));
assert($incorrectlyMarkedDynaFnNames->isEmpty(), |'dyna fns ' + $incorrectlyMarkedDynaFnNames->makeString('[', ', ', ']') + ' are incorrectly marked as ignored even though they are tested in sqlQueryToString/testSuite');
let untestedDynaFnNames = $dynaFnNames->filter(d| !$d->in($testedDynaFnNames) && !$d->in($testingIgnoredDynaFnNames));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ Class meta::relational::tests::mapping::sqlFunction::model::domain::SqlFunctionD
dayOfWeek: String[1];
dateTime: DateTime[1];
adjustDate: DateTime[1];
toBoolean: Boolean[1];
}

Class meta::relational::tests::mapping::sqlFunction::model::domain::SqlFunctionDemoForPresto
Expand Down Expand Up @@ -826,7 +827,8 @@ Mapping meta::relational::tests::mapping::sqlFunction::model::mapping::testMappi
decodeBase64Result : decodeBase64(encodeBase64(alphaNumericString)),

dateTime: dateTime,
adjustDate: adjust(dateTime, -7, 'DAYS')
adjustDate: adjust(dateTime, -7, 'DAYS'),
toBoolean: parseBoolean('true')
)

}
Expand Down
Loading