public Set<String> generateOutputColumns() { Set<String> outputColumns = new HashSet<>(); for (Command t : commands) { if (t.getOutputColumns() != null) outputColumns.addAll(t.getOutputColumns()); } return outputColumns; }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof UnassignSemanticTypeCommand) { String model = newCommand.getModel(); Iterator<ICommand> itr = commands.iterator(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (tmp.getModel().equals(model) && ((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && (tmp instanceof SetSemanticTypeCommand || tmp instanceof SetMetaPropertyCommand)) { return new ImmutablePair<>(tmp, (Object)newCommand); } } } return null; }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof OrganizeColumnsCommand) { String model = newCommand.getModel(); Iterator<ICommand> itr = commands.iterator(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (tmp.getModel().equals(model) && ((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && (tmp instanceof OrganizeColumnsCommand)) { return new ImmutablePair<>(tmp, (Object)newCommand); } } } return null; } }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof SetSemanticTypeCommand || newCommand instanceof SetMetaPropertyCommand) { String model = newCommand.getModel(); Iterator<ICommand> itr = commands.iterator(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (tmp.getModel().equals(model) && ((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && (tmp instanceof SetSemanticTypeCommand)) { return new ImmutablePair<>(tmp, (Object)newCommand); } } } return null; } }
private Map<Command, List<Command> > generateGraph() { Map<Command, List<Command> > dag = new HashMap<>(); Map<String, List<Command> > outputMapping = new HashMap<>(); for (Command command : commands) { Set<String> inputs = command.getInputColumns(); for (String input : inputs) { List<Command> outputCommands = outputMapping.get(input); if (outputCommands != null) { List<Command> edges = dag.get(command); if (edges == null) edges = new ArrayList<>(); for (Command tmp : outputCommands) { if (tmp != command) edges.add(tmp); } dag.put(command, edges); } } Set<String> outputs = command.getOutputColumns(); for (String output : outputs) { List<Command> tmp = outputMapping.get(output); if (tmp == null) tmp = new ArrayList<>(); tmp.add(command); outputMapping.put(output, tmp); } } return dag; }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof AddLiteralNodeCommand) { String nodeId = ((AddLiteralNodeCommand)newCommand).getNodeId(); if(nodeId != null) { String model = newCommand.getModel(); Iterator<ICommand> itr = commands.iterator(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (tmp.getModel().equals(model) && ((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && (tmp instanceof AddLiteralNodeCommand)) { String tmpNodeId = ((AddLiteralNodeCommand)tmp).getNodeId(); if(tmpNodeId != null && tmpNodeId.equals(nodeId)) return new ImmutablePair<>(tmp, (Object)newCommand); } } } } return null; }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof DeleteNodeCommand) { String model = newCommand.getModel(); String nodeId = ((DeleteNodeCommand)newCommand).getNodeId(); if(nodeId != null) { Iterator<ICommand> itr = commands.iterator(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (tmp.getModel().equals(model) && ((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && (tmp instanceof AddLiteralNodeCommand || tmp instanceof AddNodeCommand)) { String tmpNodeId; if(tmp instanceof AddLiteralNodeCommand) { tmpNodeId = ((AddLiteralNodeCommand)tmp).getNodeId(); } else { tmpNodeId = ((AddNodeCommand)tmp).getNodeId(); } if(tmpNodeId != null && tmpNodeId.equals(nodeId)) return new ImmutablePair<>(tmp, (Object)newCommand); } } } } return null; }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof SubmitPythonTransformationCommand) { String model = newCommand.getModel(); Iterator<ICommand> itr = commands.iterator(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && tmp.getModel().equals(model) && (tmp instanceof AddColumnCommand)) { SubmitPythonTransformationCommand py = ((SubmitPythonTransformationCommand)newCommand); JSONArray inputJSON = new JSONArray(py.getInputParameterJson()); JSONArray tmpInputJSON = new JSONArray(tmp.getInputParameterJson()); String hNodeId = HistoryJsonUtil.getStringValue("hNodeId", tmpInputJSON); HistoryJsonUtil.setArgumentValue("hNodeId", hNodeId, inputJSON); py.setInputParameterJson(inputJSON.toString()); return new ImmutablePair<>(tmp, (Object)py); } } } return null; }
@Override public Pair<ICommand, Object> consolidateCommand(List<ICommand> commands, ICommand newCommand, Workspace workspace) { if (newCommand instanceof SubmitEditPythonTransformationCommand) { Iterator<ICommand> itr = commands.iterator(); String model = newCommand.getModel(); while(itr.hasNext()) { ICommand tmp = itr.next(); if (((Command)tmp).getOutputColumns().equals(((Command)newCommand).getOutputColumns()) && tmp instanceof SubmitPythonTransformationCommand && !(tmp instanceof SubmitEditPythonTransformationCommand) && model.equals(tmp.getModel())) { SubmitPythonTransformationCommand py = (SubmitPythonTransformationCommand)tmp; SubmitPythonTransformationCommand edit = (SubmitPythonTransformationCommand)newCommand; JSONArray inputJSON = new JSONArray(py.getInputParameterJson()); JSONArray oldInputJSON = new JSONArray(py.getInputParameterJson()); HistoryJsonUtil.setArgumentValue("transformationCode", edit.getTransformationCode(), inputJSON); py.setInputParameterJson(inputJSON.toString()); py.setTransformationCode(edit.getTransformationCode()); return new ImmutablePair<>(tmp, (Object)oldInputJSON); } } } return null; }
private void placeTransformCommandByInput(Command command) { ICommand placeAfterCmd = null; Set<String> cmdInputs = command.getInputColumns(); Set<String> cmdOutputs = command.getOutputColumns(); List<Command> commandsToMove = new ArrayList<>(); for (ICommand afterCmd : worksheetCommandHistory.getCommandsAfterCommand(command, CommandTag.Transformation)) { Set<String> afterCmdOutputs = ((Command)afterCmd).getOutputColumns(); Set<String> afterCmdInputs = ((Command)afterCmd).getInputColumns(); for(String input : cmdInputs) {
public static void detectSelectionStatusChange(String worksheetId, Workspace workspace, Command command) { Worksheet worksheet = workspace.getWorksheet(worksheetId); for (Selection sel : worksheet.getSelectionManager().getAllDefinedSelection()) { Set<String> inputColumns = sel.getInputColumns(); inputColumns.retainAll(command.getOutputColumns()); if (!inputColumns.isEmpty() && !command.getCommandName().equals("OperateSelectionCommand") && !command.getCommandName().equals("ClearSelectionCommand")) sel.invalidateSelection(); if (sel.isSelectedRowsMethod() && checkSelection(sel, command, workspace.getFactory())) { sel.invalidateSelection(); } } }
private Pair<Boolean, Set<String>> detectTransformCycle(String worksheetId) { DirectedGraph<String, DefaultEdge> historyInputOutputGraph = new DefaultDirectedGraph<>(DefaultEdge.class); for (ICommand cmd : worksheetCommandHistory.getCommandsFromWorksheetIdAndCommandTag(worksheetId, CommandTag.Transformation)) { Set<String> outputs = ((Command)cmd).getOutputColumns(); Set<String> inputs = ((Command)cmd).getInputColumns(); String commandId = "Command-" + cmd.getId();
for (String hNodeId : tmp.getOutputColumns()) { HNode node = workspace.getFactory().getHNode(hNodeId); JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
outputColumns.addAll(cmd.getOutputColumns()); WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this); UpdateContainer c = new UpdateContainer();
private static boolean checkSelection(Selection sel, Command command, RepFactory factory) { Set<String> selectedRowsColumns = sel.getSelectedRowsColumns(); Set<String> outputColumns = command.getOutputColumns(); for (String parent : selectedRowsColumns) { HTable parentHT = factory.getHTable(factory.getHNode(parent).getHTableId()); for (String child : outputColumns) { HTable childHT = factory.getHTable(factory.getHNode(child).getHTableId()); if (isChildHTable(parentHT, childHT, factory)) return true; } } return false; }