public static List<List<Object>> getBulkRows(Insert insert, List<ElementSymbol> elements) throws ExpressionEvaluationException, BlockedException, TeiidComponentException { int bulkRowCount = 1; if (isBulk(insert)) { Constant c = (Constant)insert.getValues().get(0); bulkRowCount = ((List<?>)c.getValue()).size(); } List<List<Object>> tuples = new ArrayList<List<Object>>(bulkRowCount); for (int row = 0; row < bulkRowCount; row++) { List<Object> currentRow = new ArrayList<Object>(insert.getValues().size()); for (ElementSymbol symbol : elements) { int index = insert.getVariables().indexOf(symbol); Object value = null; if (index != -1) { if (isBulk(insert)) { Constant multiValue = (Constant)insert.getValues().get(index); value = ((List<?>)multiValue.getValue()).get(row); } else { Expression expr = (Expression)insert.getValues().get(index); value = Evaluator.evaluate(expr); } } currentRow.add(value); } tuples.add(currentRow); } return tuples; }
/** * Return a deep copy of this Insert. * @return Deep copy of Insert */ public Object clone() { GroupSymbol copyGroup = null; if(group != null) { copyGroup = group.clone(); } List<ElementSymbol> copyVars = LanguageObject.Util.deepClone(getVariables(), ElementSymbol.class); List<Expression> copyVals = null; if ( getValues() != null) { copyVals = LanguageObject.Util.deepClone(getValues(), Expression.class); } Insert copy = new Insert(copyGroup, copyVars, copyVals); if (this.queryExpression != null) { copy.setQueryExpression((QueryCommand)this.queryExpression.clone()); } this.copyMetadataState(copy); if (this.constraint != null) { copy.constraint = (Criteria) this.constraint.clone(); } copy.upsert = this.upsert; return copy; }
/** * Return a deep copy of this Insert. * @return Deep copy of Insert */ public Object clone() { GroupSymbol copyGroup = null; if(group != null) { copyGroup = group.clone(); } List<ElementSymbol> copyVars = LanguageObject.Util.deepClone(getVariables(), ElementSymbol.class); List<Expression> copyVals = null; if ( getValues() != null) { copyVals = LanguageObject.Util.deepClone(getValues(), Expression.class); } Insert copy = new Insert(copyGroup, copyVars, copyVals); if (this.queryExpression != null) { copy.setQueryExpression((QueryCommand)this.queryExpression.clone()); } this.copyMetadataState(copy); if (this.constraint != null) { copy.constraint = (Criteria) this.constraint.clone(); } copy.upsert = this.upsert; return copy; }
/** * Return a deep copy of this Insert. * @return Deep copy of Insert */ public Object clone() { GroupSymbol copyGroup = null; if(group != null) { copyGroup = group.clone(); } List<ElementSymbol> copyVars = LanguageObject.Util.deepClone(getVariables(), ElementSymbol.class); List<Expression> copyVals = null; if ( getValues() != null) { copyVals = LanguageObject.Util.deepClone(getValues(), Expression.class); } Insert copy = new Insert(copyGroup, copyVars, copyVals); if (this.queryExpression != null) { copy.setQueryExpression((QueryCommand)this.queryExpression.clone()); } this.copyMetadataState(copy); if (this.constraint != null) { copy.constraint = (Criteria) this.constraint.clone(); } copy.upsert = this.upsert; return copy; }
/** * Compare two Insert commands for equality. Will only evaluate to equal if * they are IDENTICAL: group is equal, value is equal and variables are equal. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof Insert)) { return false; } Insert other = (Insert) obj; return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) && EquivalenceUtil.areEqual(getValues(), other.getValues()) && EquivalenceUtil.areEqual(getVariables(), other.getVariables()) && sameOptionAndHint(other) && EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression()) && this.upsert == other.upsert; }
/** * Compare two Insert commands for equality. Will only evaluate to equal if * they are IDENTICAL: group is equal, value is equal and variables are equal. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof Insert)) { return false; } Insert other = (Insert) obj; return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) && EquivalenceUtil.areEqual(getValues(), other.getValues()) && EquivalenceUtil.areEqual(getVariables(), other.getVariables()) && sameOptionAndHint(other) && EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression()) && this.upsert == other.upsert; }
/** * Compare two Insert commands for equality. Will only evaluate to equal if * they are IDENTICAL: group is equal, value is equal and variables are equal. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { // Quick same object test if(this == obj) { return true; } // Quick fail tests if(!(obj instanceof Insert)) { return false; } Insert other = (Insert) obj; return EquivalenceUtil.areEqual(getGroup(), other.getGroup()) && EquivalenceUtil.areEqual(getValues(), other.getValues()) && EquivalenceUtil.areEqual(getVariables(), other.getVariables()) && sameOptionAndHint(other) && EquivalenceUtil.areEqual(getQueryExpression(), other.getQueryExpression()) && this.upsert == other.upsert; }
/** * Test for defect 12087 - Insert with implicit conversion from integer to short */ @Test public void testImplConversionBetweenIntAndShort() throws Exception { Insert command = (Insert)QueryParser.getQueryParser().parseCommand("Insert into pm5.g3(e2) Values(100)"); //$NON-NLS-1$ QueryResolver.resolveCommand(command, metadata); assertTrue(((Expression)command.getValues().get(0)).getType() == DataTypeManager.DefaultDataClasses.SHORT); }
Constant c = (Constant)insert.getValues().get(0); assertTrue(c.isMultiValued()); assertTrue(((List<?>)c.getValue()).get(0) instanceof BinaryType);
/** * Constants will now auto resolve if they are consistently representable in the target type */ @Test public void testDefect23257() throws Exception{ CreateProcedureCommand command = (CreateProcedureCommand) helpResolve("EXEC pm6.vsp59()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ CommandStatement cs = (CommandStatement)command.getBlock().getStatements().get(1); Insert insert = (Insert)cs.getCommand(); assertEquals(DataTypeManager.DefaultDataClasses.SHORT, ((Expression)insert.getValues().get(1)).getType()); }
public void visit(Insert obj) { preVisitVisitor(obj); visitNode(obj.getGroup()); visitNodes(obj.getVariables()); visitNodes(obj.getValues()); if(deep && obj.getQueryExpression()!=null) { visitNode(obj.getQueryExpression()); } visitNode(obj.getOption()); postVisitVisitor(obj); } public void visit(Create obj) {
public void visit(Insert obj) { preVisitVisitor(obj); visitNode(obj.getGroup()); visitNodes(obj.getVariables()); visitNodes(obj.getValues()); if(deep && obj.getQueryExpression()!=null) { visitNode(obj.getQueryExpression()); } visitNode(obj.getOption()); postVisitVisitor(obj); } public void visit(Create obj) {
public void visit(Insert obj) { preVisitVisitor(obj); visitNode(obj.getGroup()); visitNodes(obj.getVariables()); visitNodes(obj.getValues()); if(deep && obj.getQueryExpression()!=null) { visitNode(obj.getQueryExpression()); } visitNode(obj.getOption()); postVisitVisitor(obj); } public void visit(Create obj) {