Package org.apache.sysds.runtime.util
Class ProgramConverter
- java.lang.Object
- 
- org.apache.sysds.runtime.util.ProgramConverter
 
- 
 public class ProgramConverter extends Object Program converter functionalities for (1) creating deep copies of program blocks, instructions, function program blocks, and (2) serializing and parsing of programs, program blocks, functions program blocks.
- 
- 
Field Summary
 - 
Constructor SummaryConstructors Constructor Description ProgramConverter()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static InstructioncloneInstruction(Instruction oInst, long pid, boolean plain, boolean cpFunctions)static ExecutionContextcreateDeepCopyExecutionContext(ExecutionContext ec)Creates a deep copy of the given execution context.static ForProgramBlockcreateDeepCopyForProgramBlock(ForProgramBlock fpb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy)static voidcreateDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain)This creates a deep copy of a function program block.static FunctionProgramBlockcreateDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, Set<String> fnStack, Set<String> fnCreated)static FunctionProgramBlockcreateDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, Set<String> fnStack, Set<String> fnCreated, long pid)static FunctionProgramBlockcreateDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, Set<String> fnStack, Set<String> fnCreated, long pid, int IDPrefix, boolean plain)static FunctionStatementBlockcreateDeepCopyFunctionStatementBlock(FunctionStatementBlock fsb, Set<String> fnStack, Set<String> fnCreated)static IfProgramBlockcreateDeepCopyIfProgramBlock(IfProgramBlock ipb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy)static ArrayList<Instruction>createDeepCopyInstructionSet(ArrayList<Instruction> instSet, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean cpFunctions)Creates a deep copy of an array of instructions and replaces the placeholders of parworker IDs with the concrete IDs of this parfor instance.static ParForProgramBlockcreateDeepCopyParForProgramBlock(ParForProgramBlock pfpb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy)static WhileProgramBlockcreateDeepCopyWhileProgramBlock(WhileProgramBlock wpb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy)static ForStatementBlockcreateForStatementBlockCopy(ForStatementBlock sb, boolean forceDeepCopy)static IfStatementBlockcreateIfStatementBlockCopy(IfStatementBlock sb, boolean forceDeepCopy)static ForProgramBlockcreateShallowCopyForProgramBlock(ForProgramBlock fpb, Program prog)static StatementBlockcreateStatementBlockCopy(StatementBlock sb, long pid, boolean plain, boolean forceDeepCopy)static WhileStatementBlockcreateWhileStatementBlockCopy(WhileStatementBlock sb, boolean forceDeepCopy)static Object[]parseDataObject(String in)NOTE: MRJobConfiguration cannot be used for the general case because program blocks and related symbol tables can be hierarchically structured.static ParForBodyparseParForBody(String in, int id)static ParForBodyparseParForBody(String in, int id, boolean inSpark)static ProgramparseProgram(String in, int id)static SparkPSBodyparseSparkPSBody(String in, int id)static ArrayList<ProgramBlock>rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks, long pid, int IDPrefix, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy)This recursively creates a deep copy of program blocks and transparently replaces filenames according to the specified parallel worker in order to avoid conflicts between parworkers.static StatementBlockrCreateDeepCopyStatementBlock(StatementBlock sb)static StringsaveReplaceFilenameThreadID(String fname, String pattern, String replace)static StringserializeDataObject(String key, Data dat)static StringserializeList(List<String> elements)static StringserializeList(List<String> elements, String delim)static StringserializeParForBody(ParForBody body)static StringserializeParForBody(ParForBody body, HashMap<String,byte[]> clsMap)static StringserializeProgram(Program prog, ArrayList<ProgramBlock> pbs, HashMap<String,byte[]> clsMap)static StringserializeResultVariables(List<ParForStatementBlock.ResultVar> vars)static StringserializeSparkPSBody(SparkPSBody body, HashMap<String,byte[]> clsMap)
 
- 
- 
- 
Field Detail- 
NEWLINEpublic static final String NEWLINE - See Also:
- Constant Field Values
 
 - 
COMPONENTS_DELIMpublic static final String COMPONENTS_DELIM - See Also:
- Constant Field Values
 
 - 
ELEMENT_DELIMpublic static final String ELEMENT_DELIM - See Also:
- Constant Field Values
 
 - 
ELEMENT_DELIM2public static final String ELEMENT_DELIM2 - See Also:
- Constant Field Values
 
 - 
DATA_FIELD_DELIMpublic static final String DATA_FIELD_DELIM - See Also:
- Constant Field Values
 
 - 
KEY_VALUE_DELIMpublic static final String KEY_VALUE_DELIM - See Also:
- Constant Field Values
 
 - 
LEVELINpublic static final String LEVELIN - See Also:
- Constant Field Values
 
 - 
LEVELOUTpublic static final String LEVELOUT - See Also:
- Constant Field Values
 
 - 
EMPTYpublic static final String EMPTY - See Also:
- Constant Field Values
 
 - 
DASHpublic static final String DASH - See Also:
- Constant Field Values
 
 - 
REFpublic static final String REF - See Also:
- Constant Field Values
 
 - 
LIST_ELEMENT_DELIMpublic static final String LIST_ELEMENT_DELIM - See Also:
- Constant Field Values
 
 - 
CDATA_BEGINpublic static final String CDATA_BEGIN - See Also:
- Constant Field Values
 
 - 
CDATA_ENDpublic static final String CDATA_END - See Also:
- Constant Field Values
 
 - 
PROG_BEGINpublic static final String PROG_BEGIN - See Also:
- Constant Field Values
 
 - 
PROG_ENDpublic static final String PROG_END - See Also:
- Constant Field Values
 
 - 
VARS_BEGINpublic static final String VARS_BEGIN - See Also:
- Constant Field Values
 
 - 
VARS_ENDpublic static final String VARS_END - See Also:
- Constant Field Values
 
 - 
PBS_BEGINpublic static final String PBS_BEGIN - See Also:
- Constant Field Values
 
 - 
PBS_ENDpublic static final String PBS_END - See Also:
- Constant Field Values
 
 - 
INST_BEGINpublic static final String INST_BEGIN - See Also:
- Constant Field Values
 
 - 
INST_ENDpublic static final String INST_END - See Also:
- Constant Field Values
 
 - 
EC_BEGINpublic static final String EC_BEGIN - See Also:
- Constant Field Values
 
 - 
EC_ENDpublic static final String EC_END - See Also:
- Constant Field Values
 
 - 
PB_BEGINpublic static final String PB_BEGIN - See Also:
- Constant Field Values
 
 - 
PB_ENDpublic static final String PB_END - See Also:
- Constant Field Values
 
 - 
PB_WHILEpublic static final String PB_WHILE - See Also:
- Constant Field Values
 
 - 
PB_FORpublic static final String PB_FOR - See Also:
- Constant Field Values
 
 - 
PB_PARFORpublic static final String PB_PARFOR - See Also:
- Constant Field Values
 
 - 
PB_IFpublic static final String PB_IF - See Also:
- Constant Field Values
 
 - 
PB_FCpublic static final String PB_FC - See Also:
- Constant Field Values
 
 - 
PB_EFCpublic static final String PB_EFC - See Also:
- Constant Field Values
 
 - 
CONF_STATSpublic static final String CONF_STATS - See Also:
- Constant Field Values
 
 - 
PARFORBODY_BEGINpublic static final String PARFORBODY_BEGIN - See Also:
- Constant Field Values
 
 - 
PARFORBODY_ENDpublic static final String PARFORBODY_END - See Also:
- Constant Field Values
 
 - 
PSBODY_BEGINpublic static final String PSBODY_BEGIN - See Also:
- Constant Field Values
 
 - 
PSBODY_ENDpublic static final String PSBODY_END - See Also:
- Constant Field Values
 
 - 
NOT_SUPPORTED_SPARK_INSTRUCTIONpublic static final String NOT_SUPPORTED_SPARK_INSTRUCTION - See Also:
- Constant Field Values
 
 - 
NOT_SUPPORTED_SPARK_PARFORpublic static final String NOT_SUPPORTED_SPARK_PARFOR - See Also:
- Constant Field Values
 
 - 
NOT_SUPPORTED_PBpublic static final String NOT_SUPPORTED_PB - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
createDeepCopyExecutionContextpublic static ExecutionContext createDeepCopyExecutionContext(ExecutionContext ec) throws CloneNotSupportedException Creates a deep copy of the given execution context. For rt_platform=Hadoop, execution context has a symbol table.- Parameters:
- ec- execution context
- Returns:
- execution context
- Throws:
- CloneNotSupportedException- if CloneNotSupportedException occurs
 
 - 
rcreateDeepCopyProgramBlockspublic static ArrayList<ProgramBlock> rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks, long pid, int IDPrefix, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy) This recursively creates a deep copy of program blocks and transparently replaces filenames according to the specified parallel worker in order to avoid conflicts between parworkers. This happens recursively in order to support arbitrary control-flow constructs within a parfor.- Parameters:
- childBlocks- child program blocks
- pid- ?
- IDPrefix- ?
- fnStack- ?
- fnCreated- ?
- plain- if true, full deep copy without id replacement
- forceDeepCopy- if true, force deep copy
- Returns:
- list of program blocks
 
 - 
createDeepCopyWhileProgramBlockpublic static WhileProgramBlock createDeepCopyWhileProgramBlock(WhileProgramBlock wpb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy) 
 - 
createDeepCopyIfProgramBlockpublic static IfProgramBlock createDeepCopyIfProgramBlock(IfProgramBlock ipb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy) 
 - 
createDeepCopyForProgramBlockpublic static ForProgramBlock createDeepCopyForProgramBlock(ForProgramBlock fpb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy) 
 - 
createShallowCopyForProgramBlockpublic static ForProgramBlock createShallowCopyForProgramBlock(ForProgramBlock fpb, Program prog) 
 - 
createDeepCopyParForProgramBlockpublic static ParForProgramBlock createDeepCopyParForProgramBlock(ParForProgramBlock pfpb, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean forceDeepCopy) 
 - 
createDeepCopyFunctionProgramBlockpublic static void createDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain) This creates a deep copy of a function program block. The central reference to singletons of function program blocks poses the need for explicit copies in order to prevent conflicting writes of temporary variables (see ExternalFunctionProgramBlock.- Parameters:
- namespace- function namespace
- oldName- ?
- pid- ?
- IDPrefix- ?
- prog- runtime program
- fnStack- ?
- fnCreated- ?
- plain- ?
 
 - 
createDeepCopyFunctionProgramBlockpublic static FunctionProgramBlock createDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, Set<String> fnStack, Set<String> fnCreated) 
 - 
createDeepCopyFunctionProgramBlockpublic static FunctionProgramBlock createDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, Set<String> fnStack, Set<String> fnCreated, long pid) 
 - 
createDeepCopyFunctionProgramBlockpublic static FunctionProgramBlock createDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, Set<String> fnStack, Set<String> fnCreated, long pid, int IDPrefix, boolean plain) 
 - 
createDeepCopyInstructionSetpublic static ArrayList<Instruction> createDeepCopyInstructionSet(ArrayList<Instruction> instSet, long pid, int IDPrefix, Program prog, Set<String> fnStack, Set<String> fnCreated, boolean plain, boolean cpFunctions) Creates a deep copy of an array of instructions and replaces the placeholders of parworker IDs with the concrete IDs of this parfor instance. This is a helper method uses for generating deep copies of program blocks.- Parameters:
- instSet- list of instructions
- pid- ?
- IDPrefix- ?
- prog- runtime program
- fnStack- ?
- fnCreated- ?
- plain- ?
- cpFunctions- ?
- Returns:
- list of instructions
 
 - 
cloneInstructionpublic static Instruction cloneInstruction(Instruction oInst, long pid, boolean plain, boolean cpFunctions) 
 - 
createDeepCopyFunctionStatementBlockpublic static FunctionStatementBlock createDeepCopyFunctionStatementBlock(FunctionStatementBlock fsb, Set<String> fnStack, Set<String> fnCreated) 
 - 
rCreateDeepCopyStatementBlockpublic static StatementBlock rCreateDeepCopyStatementBlock(StatementBlock sb) 
 - 
createStatementBlockCopypublic static StatementBlock createStatementBlockCopy(StatementBlock sb, long pid, boolean plain, boolean forceDeepCopy) 
 - 
createIfStatementBlockCopypublic static IfStatementBlock createIfStatementBlockCopy(IfStatementBlock sb, boolean forceDeepCopy) 
 - 
createWhileStatementBlockCopypublic static WhileStatementBlock createWhileStatementBlockCopy(WhileStatementBlock sb, boolean forceDeepCopy) 
 - 
createForStatementBlockCopypublic static ForStatementBlock createForStatementBlockCopy(ForStatementBlock sb, boolean forceDeepCopy) 
 - 
serializeSparkPSBodypublic static String serializeSparkPSBody(SparkPSBody body, HashMap<String,byte[]> clsMap) 
 - 
serializeParForBodypublic static String serializeParForBody(ParForBody body) 
 - 
serializeParForBodypublic static String serializeParForBody(ParForBody body, HashMap<String,byte[]> clsMap) 
 - 
serializeProgrampublic static String serializeProgram(Program prog, ArrayList<ProgramBlock> pbs, HashMap<String,byte[]> clsMap) 
 - 
serializeResultVariablespublic static String serializeResultVariables(List<ParForStatementBlock.ResultVar> vars) 
 - 
parseSparkPSBodypublic static SparkPSBody parseSparkPSBody(String in, int id) 
 - 
parseParForBodypublic static ParForBody parseParForBody(String in, int id) 
 - 
parseParForBodypublic static ParForBody parseParForBody(String in, int id, boolean inSpark) 
 - 
parseDataObjectpublic static Object[] parseDataObject(String in) NOTE: MRJobConfiguration cannot be used for the general case because program blocks and related symbol tables can be hierarchically structured.- Parameters:
- in- data object as string
- Returns:
- array of objects
 
 
- 
 
-