Package org.apache.sysds.parser
Class Expression
- java.lang.Object
- 
- org.apache.sysds.parser.Expression
 
- 
- All Implemented Interfaces:
- ParseInfo
 - Direct Known Subclasses:
- BinaryExpression,- BooleanExpression,- ExpressionList,- Identifier,- IterablePredicate,- RelationalExpression
 
 public abstract class Expression extends Object implements ParseInfo 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classExpression.BinaryOpBinary operators.static classExpression.BooleanOpBoolean operators.static classExpression.DataOpData operators.static classExpression.FunctCallOpFunction call operators.static classExpression.RelationalOpRelational operators.
 - 
Constructor SummaryConstructors Constructor Description Expression()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Types.DataTypecomputeDataType(Expression expression1, Expression expression2, boolean cast)Compute data type based on expressions.static Types.DataTypecomputeDataType(Identifier identifier1, Identifier identifier2, boolean cast)Compute data type based on identifiers.static Types.ValueTypecomputeValueType(Expression expr1, Types.ValueType v1, Types.ValueType v2, boolean cast)static Types.ValueTypecomputeValueType(Expression expression1, Expression expression2, boolean cast)Compute value type based on expressions.static Types.ValueTypecomputeValueType(Identifier identifier1, Identifier identifier2, boolean cast)Compute value type based on identifiers.static Types.FileFormatconvertFormatType(String format)Convert string format type toHop.FileFormatTypes.booleanequals(Object that)intgetBeginColumn()intgetBeginLine()static MatrixCharacteristicsgetBinaryMatrixCharacteristics(Expression expression1, Expression expression2)Returns the matrix characteristics for scalar-scalar, scalar-matrix, matrix-scalar, matrix-matrix operations.static Expression.BinaryOpgetBinaryOp(String val)Convert string value to binary operator.static Expression.BooleanOpgetBooleanOp(String val)Convert string value to boolean operator.intgetEndColumn()intgetEndLine()StringgetFilename()IdentifiergetOutput()Obtain identifier.Identifier[]getOutputs()Obtain identifiers.ArrayList<String>getParseExceptionList()static Expression.RelationalOpgetRelationalOp(String val)Convert string value to relational operator.static StringgetTempName()Obtain temporary name ("parsertemp" + _tempId) for expression.StringgetText()inthashCode()StringprintErrorLocation()StringprintInfoLocation()Return info message containing the filename, the beginning line position, and the beginning column position.StringprintWarningLocation()voidraiseValidateError(String message)Throw a LanguageException with the message.voidraiseValidateError(String message, boolean conditional)Throw a LanguageException with the message if conditional isfalse; otherwise log the message as a warning.voidraiseValidateError(String msg, boolean conditional, String errorCode)Throw a LanguageException with the message (and optional error code) if conditional isfalse; otherwise log the message as a warning.abstract ExpressionrewriteExpression(String prefix)voidsetBeginColumn(int passed)voidsetBeginLine(int passed)voidsetCtxValues(org.antlr.v4.runtime.ParserRuleContext ctx)Set ParserRuleContext values (begin line, begin column, end line, end column, and text).voidsetCtxValuesAndFilename(org.antlr.v4.runtime.ParserRuleContext ctx, String filename)Set ParserRuleContext values (begin line, begin column, end line, end column, and text) and file name.voidsetEndColumn(int passed)voidsetEndLine(int passed)voidsetFilename(String passed)voidsetOutput(Identifier output)voidsetParseExceptionList(ArrayList<String> passed)voidsetParseInfo(ParseInfo parseInfo)Set parse information.voidsetText(String text)voidvalidateExpression(HashMap<String,DataIdentifier> ids, HashMap<String,ConstIdentifier> currConstVars, boolean conditional)voidvalidateExpression(MultiAssignmentStatement mas, HashMap<String,DataIdentifier> ids, HashMap<String,ConstIdentifier> currConstVars, boolean conditional)abstract VariableSetvariablesRead()abstract VariableSetvariablesUpdated()
 
- 
- 
- 
Method Detail- 
rewriteExpressionpublic abstract Expression rewriteExpression(String prefix) 
 - 
setOutputpublic void setOutput(Identifier output) 
 - 
getOutputpublic Identifier getOutput() Obtain identifier.- Returns:
- Identifier
 
 - 
getOutputspublic Identifier[] getOutputs() Obtain identifiers.- Returns:
- Identifiers
 
 - 
validateExpressionpublic void validateExpression(HashMap<String,DataIdentifier> ids, HashMap<String,ConstIdentifier> currConstVars, boolean conditional) 
 - 
validateExpressionpublic void validateExpression(MultiAssignmentStatement mas, HashMap<String,DataIdentifier> ids, HashMap<String,ConstIdentifier> currConstVars, boolean conditional) 
 - 
getBinaryOppublic static Expression.BinaryOp getBinaryOp(String val) Convert string value to binary operator.- Parameters:
- val- String value ('+', '-', '*', '/', '%%', '%/%', '^', %*%')
- Returns:
- Binary operator (BinaryOp.PLUS,BinaryOp.MINUS,BinaryOp.MULT,BinaryOp.DIV,BinaryOp.MODULUS,BinaryOp.INTDIV,BinaryOp.POW,BinaryOp.MATMULT). ReturnsBinaryOp.INVALIDif string value not recognized.
 
 - 
getRelationalOppublic static Expression.RelationalOp getRelationalOp(String val) Convert string value to relational operator.- Parameters:
- val- String value ('<', '<=', '>', '>=', '==', '!=')
- Returns:
- Relational operator (RelationalOp.LESS,RelationalOp.LESSEQUAL,RelationalOp.GREATER,RelationalOp.GREATEREQUAL,RelationalOp.EQUAL,RelationalOp.NOTEQUAL). ReturnsRelationalOp.INVALIDif string value not recognized.
 
 - 
getBooleanOppublic static Expression.BooleanOp getBooleanOp(String val) Convert string value to boolean operator.- Parameters:
- val- String value ('&&', '&', '||', '|', '!')
- Returns:
- Boolean operator (BooleanOp.CONDITIONALAND,BooleanOp.LOGICALAND,BooleanOp.CONDITIONALOR,BooleanOp.LOGICALOR,BooleanOp.NOT). ReturnsBooleanOp.INVALIDif string value not recognized.
 
 - 
convertFormatTypepublic static Types.FileFormat convertFormatType(String format) Convert string format type toHop.FileFormatTypes.- Parameters:
- format- String format type ("text", "binary", "mm", "csv")
- Returns:
- Format as Hop.FileFormatTypes. Can beFileFormatTypes.TEXT,FileFormatTypes.BINARY,FileFormatTypes.MM, orFileFormatTypes.CSV. Unrecognized type is set toFileFormatTypes.TEXT.
 
 - 
getTempNamepublic static String getTempName() Obtain temporary name ("parsertemp" + _tempId) for expression. Used to construct Hops from parse tree.- Returns:
- Temporary name of expression.
 
 - 
variablesReadpublic abstract VariableSet variablesRead() 
 - 
variablesUpdatedpublic abstract VariableSet variablesUpdated() 
 - 
computeDataTypepublic static Types.DataType computeDataType(Expression expression1, Expression expression2, boolean cast) Compute data type based on expressions. The identifier for each expression is obtained and passed tocomputeDataType(Identifier, Identifier, boolean). If the identifiers have the same data type, the shared data type is returned. Otherwise, ifcastistrueand one of the identifiers is a matrix and the other identifier is a scalar, returnDataType.MATRIX. Otherwise, throw a LanguageException.- Parameters:
- expression1- First expression
- expression2- Second expression
- cast- Whether a cast should potentially be performed
- Returns:
- The data type (Types.DataType)
 
 - 
computeDataTypepublic static Types.DataType computeDataType(Identifier identifier1, Identifier identifier2, boolean cast) Compute data type based on identifiers. If the identifiers have the same data type, the shared data type is returned. Otherwise, ifcastistrueand one of the identifiers is a matrix and the other identifier is a scalar, returnDataType.MATRIX. Otherwise, throw a LanguageException.- Parameters:
- identifier1- First identifier
- identifier2- Second identifier
- cast- Whether a cast should potentially be performed
- Returns:
- The data type (Types.DataType)
 
 - 
computeValueTypepublic static Types.ValueType computeValueType(Expression expression1, Expression expression2, boolean cast) Compute value type based on expressions. The identifier for each expression is obtained and passed tocomputeValueType(Identifier, Identifier, boolean). If the identifiers have the same value type, the shared value type is returned. Otherwise, ifcastistrueand one value type is a double and the other is an int, returnValueType.DOUBLE. Ifcastistrueand one value type is a string or the other value type is a string, returnValueType.STRING. Otherwise, throw a LanguageException.- Parameters:
- expression1- First expression
- expression2- Second expression
- cast- Whether a cast should potentially be performed
- Returns:
- The value type (Types.ValueType)
 
 - 
computeValueTypepublic static Types.ValueType computeValueType(Identifier identifier1, Identifier identifier2, boolean cast) Compute value type based on identifiers. If the identifiers have the same value type, the shared value type is returned. Otherwise, ifcastistrueand one value type is a double and the other is an int, returnValueType.DOUBLE. Ifcastistrueand one value type is a string or the other value type is a string, returnValueType.STRING. Otherwise, throw a LanguageException.- Parameters:
- identifier1- First identifier
- identifier2- Second identifier
- cast- Whether a cast should potentially be performed
- Returns:
- The value type (Types.ValueType)
 
 - 
computeValueTypepublic static Types.ValueType computeValueType(Expression expr1, Types.ValueType v1, Types.ValueType v2, boolean cast) 
 - 
raiseValidateErrorpublic void raiseValidateError(String message) Throw a LanguageException with the message.- Parameters:
- message- the error message
 
 - 
raiseValidateErrorpublic void raiseValidateError(String message, boolean conditional) Throw a LanguageException with the message if conditional isfalse; otherwise log the message as a warning.- Parameters:
- message- the error (or warning) message
- conditional- if- true, display log warning message. Otherwise, the message will be thrown as a LanguageException
 
 - 
raiseValidateErrorpublic void raiseValidateError(String msg, boolean conditional, String errorCode) Throw a LanguageException with the message (and optional error code) if conditional isfalse; otherwise log the message as a warning.- Parameters:
- msg- the error (or warning) message
- conditional- if- true, display log warning message. Otherwise, the message (and optional error code) will be thrown as a LanguageException
- errorCode- optional error code
 
 - 
getBinaryMatrixCharacteristicspublic static MatrixCharacteristics getBinaryMatrixCharacteristics(Expression expression1, Expression expression2) Returns the matrix characteristics for scalar-scalar, scalar-matrix, matrix-scalar, matrix-matrix operations. This method is aware of potentially unknowns and matrix-vector (col/row) operations.- Parameters:
- expression1- The first expression
- expression2- The second expression
- Returns:
- matrix characteristics [1] is the number of columns (clen), [2] is the number of rows in a block (blen), and [3] is the number of columns in a block (blen). Default (unknown) values are -1. Scalar values are all 0.
 
 - 
setFilenamepublic void setFilename(String passed) - Specified by:
- setFilenamein interface- ParseInfo
 
 - 
setBeginLinepublic void setBeginLine(int passed) - Specified by:
- setBeginLinein interface- ParseInfo
 
 - 
setBeginColumnpublic void setBeginColumn(int passed) - Specified by:
- setBeginColumnin interface- ParseInfo
 
 - 
setEndLinepublic void setEndLine(int passed) - Specified by:
- setEndLinein interface- ParseInfo
 
 - 
setEndColumnpublic void setEndColumn(int passed) - Specified by:
- setEndColumnin interface- ParseInfo
 
 - 
setParseInfopublic void setParseInfo(ParseInfo parseInfo) Set parse information.- Parameters:
- parseInfo- parse information, such as beginning line position, beginning column position, ending line position, ending column position, text, and filename
 
 - 
setCtxValuespublic void setCtxValues(org.antlr.v4.runtime.ParserRuleContext ctx) Set ParserRuleContext values (begin line, begin column, end line, end column, and text).- Parameters:
- ctx- the antlr ParserRuleContext
 
 - 
setCtxValuesAndFilenamepublic void setCtxValuesAndFilename(org.antlr.v4.runtime.ParserRuleContext ctx, String filename)Set ParserRuleContext values (begin line, begin column, end line, end column, and text) and file name.- Parameters:
- ctx- the antlr ParserRuleContext
- filename- the filename (if it exists)
 
 - 
getFilenamepublic String getFilename() - Specified by:
- getFilenamein interface- ParseInfo
 
 - 
getBeginLinepublic int getBeginLine() - Specified by:
- getBeginLinein interface- ParseInfo
 
 - 
getBeginColumnpublic int getBeginColumn() - Specified by:
- getBeginColumnin interface- ParseInfo
 
 - 
getEndLinepublic int getEndLine() - Specified by:
- getEndLinein interface- ParseInfo
 
 - 
getEndColumnpublic int getEndColumn() - Specified by:
- getEndColumnin interface- ParseInfo
 
 - 
printErrorLocationpublic String printErrorLocation() 
 - 
printWarningLocationpublic String printWarningLocation() 
 - 
printInfoLocationpublic String printInfoLocation() Return info message containing the filename, the beginning line position, and the beginning column position.- Returns:
- the info message
 
 
- 
 
-