Skip to content

Commit

Permalink
Code review suggestion (#11)
Browse files Browse the repository at this point in the history
* Code review suggestion

Changes string literal to "throwing an exception" when processing
a not supported element.

* Code review suggestion

Add support for aggregate errors
  • Loading branch information
sfc-gh-lfallasavendano committed Jan 8, 2024
1 parent 8c61b78 commit 4689058
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Morphir/Scala/AST.elm
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ type Value
| ForComp (List Generator) Value
| TypeAscripted Value Type
| New Path Name (List ArgValue)
| Throw Value


{-| -}
Expand Down
2 changes: 2 additions & 0 deletions src/Morphir/Scala/PrettyPrinter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ mapValue opt value =
, mapType opt tpe
, ")"
]
Throw exceptionExpr ->
"throw " ++ (mapValue opt exceptionExpr)


mapPattern : Pattern -> Doc
Expand Down
15 changes: 10 additions & 5 deletions src/Morphir/Snowpark/AggregateMapping.elm
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ processRecords lambdaInfo functionToApply functionName mappingFunc columnNameLis
variables |> List.filterMap (\x -> x) |> List.map generateFunctionFromColumnRecords

_ ->
[ Scala.ArgValue Nothing (Scala.Literal (Scala.StringLit "Unsupported Record")) ]
[ Scala.ArgValue Nothing (defaultValueForUnsupportedElement "Unsupported Record") ]


generateFunctionFromColumnRecords : ( String, Scala.Value, Scala.Value ) -> Scala.ArgValue
generateFunctionFromColumnRecords ( funcName, columnName, aliasValue ) =
if String.contains "Unsupported" funcName then
Scala.ArgValue Nothing <| Scala.Literal (Scala.StringLit "Unsupported column")
Scala.ArgValue Nothing <| defaultValueForUnsupportedElement "Unsupported column"

else
Constants.applySnowparkFunc funcName [ columnName ] |> joinWithAlias aliasValue
Expand Down Expand Up @@ -98,7 +98,7 @@ processRecordsVariables lambdaInfo ( mapValue, ctx ) functionFromLambda function
Just <| ( "Unsupported variable", Scala.Literal (Scala.StringLit ("UnSupported variable for " ++ Name.toCamelCase name)), [ "Unsupported" ] )

_ ->
Just <| ( "Unsupported field", Scala.Literal (Scala.StringLit "UnSupported field from Record"), [ "Unsupported field" ] )
Just <| ( "Unsupported field", defaultValueForUnsupportedElement "Unsupported field from Record", [ "Unsupported field" ] )


getFunctionVariable : TypedValue -> Constants.MappingFunc -> Constants.LambdaInfo ta -> Maybe ( String, Scala.Value, Name.Name )
Expand All @@ -111,7 +111,7 @@ getFunctionVariable variableInfo mappingFunc lambdaInfo =
Just ( "count", Constants.applySnowparkFunc "col" [ Scala.Literal (Scala.StringLit (Name.toCamelCase lambdaInfo.groupByName)) ], [ "count" ] )

_ ->
Just ( "Unsupported", Scala.Literal (Scala.StringLit "Unsupported Reference"), [] )
Just ( "Unsupported", defaultValueForUnsupportedElement "Unsupported Reference", [] )


concatFunctions : Constants.VariableInformation -> List Scala.ArgValue
Expand Down Expand Up @@ -224,7 +224,12 @@ getVariable value ( mapValue, ctx ) =
Just ( func, column, columnName )

_ ->
Just ( "Unsupported", Scala.Literal (Scala.StringLit "Unsupported Reference"), [] )
Just ( "Unsupported", defaultValueForUnsupportedElement "Unsupported Reference", [] )


defaultValueForUnsupportedElement : String -> Scala.Value
defaultValueForUnsupportedElement description =
Scala.Throw (Scala.New [] "Exception" [ Scala.ArgValue Nothing (Scala.Literal (Scala.StringLit description)) ])


getColumnName : TypedValue -> Name.Name
Expand Down
2 changes: 1 addition & 1 deletion src/Morphir/Snowpark/ReferenceUtils.elm
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ getFunctionInputTypes tpe =

errorValueAndIssue : GenerationIssue -> ( Scala.Value, List GenerationIssue )
errorValueAndIssue issue =
( Scala.Literal (Scala.StringLit issue), [ issue ] )
( Scala.Throw (Scala.New [] "Exception" [ Scala.ArgValue Nothing (Scala.Literal (Scala.StringLit issue)) ]), [ issue ] )


curryCall : ( TypedValue, List TypedValue ) -> TypedValue
Expand Down
4 changes: 3 additions & 1 deletion src/Morphir/Snowpark/UserDefinedFunctionMapping.elm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ tryToConvertUserFunctionCall ( func, args ) mapValue ctx =
( List.foldl (\a c -> Scala.Apply c [ a ]) (Scala.Apply funcReference [ first ]) rest, issues )

else
( Scala.Literal (Scala.StringLit "Call not generated"), [ "Call to function not generated: " ++ FQName.toString functionName ] )
( Scala.Throw (Scala.New [] "Exception" [ Scala.ArgValue Nothing (Scala.Literal (Scala.StringLit "Call not generated")) ])
, [ "Call to function not generated: " ++ FQName.toString functionName ]
)

ValueIR.Constructor _ constructorName ->
if isRecordWithSimpleTypes constructorName ctx.typesContextInfo then
Expand Down

0 comments on commit 4689058

Please sign in to comment.