@Override public boolean next(ImmutableBytesWritable key, Result value) throws IOException { if (!delegate.nextKeyValue()) { return false; } ImmutableBytesWritable currentKey = delegate.getCurrentKey(); key.set(currentKey.get(), currentKey.getOffset(), currentKey.getLength()); value.copyFrom(delegate.getCurrentValue()); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression childExpr = children.get(0); PDataType dataType = childExpr.getDataType(); if (childExpr.evaluate(tuple, ptr)) { if (ptr.getLength()==0) { return true; } int ret = ((PNumericType) dataType).signum(ptr, childExpr.getSortOrder()); ptr.set(RESULT[ret + 1]); return true; } return false; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { PDataType returnType = getDataType(); Expression arg1Expr = children.get(0); if (!arg1Expr.evaluate(tuple, ptr)) return false; if (ptr.getLength() == 0) return true; double arg1 = JavaMathOneArgumentFunction.getArg(arg1Expr, ptr); Expression arg2Expr = (children.size() <= 1) ? null : children.get(1); double arg2; if (arg2Expr != null && !arg2Expr.evaluate(tuple, ptr)) return false; if (arg2Expr == null || ptr.getLength() == 0) { ptr.set(ByteUtil.EMPTY_BYTE_ARRAY); return true; } else { arg2 = JavaMathOneArgumentFunction.getArg(arg2Expr, ptr); } ptr.set(new byte[returnType.getByteSize()]); returnType.getCodec().encodeDouble(compute(arg1, arg2), ptr); return true; }
@Override protected int compare(Tuple t1, Tuple t2) { for (int i = 0; i < orderByColumns.size(); i++) { OrderByExpression order = orderByColumns.get(i); Expression orderExpr = order.getExpression(); boolean isNull1 = !orderExpr.evaluate(t1, ptr1) || ptr1.getLength() == 0; boolean isNull2 = !orderExpr.evaluate(t2, ptr2) || ptr2.getLength() == 0; if (isNull1 && isNull2) { continue; } else if (isNull1) { return order.isNullsLast() ? 1 : -1; } else if (isNull2) { return order.isNullsLast() ? -1 : 1; } int cmp = ptr1.compareTo(ptr2); if (cmp == 0) { continue; } return order.isAscending() ? cmp : -cmp; } return 0; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { // get binary data parameter Expression dataExpr = children.get(0); if (!dataExpr.evaluate(tuple, ptr)) return false; if (ptr.getLength()==0) return true; // set result ((PBinaryBase) dataExpr.getDataType()).octetLength(ptr, dataExpr.getSortOrder(), ptr); return true; }
@Override public void pad(ImmutableBytesWritable ptr, Integer maxLength, SortOrder sortOrder) { if (ptr.getLength() >= maxLength) { return; } byte[] newBytes = new byte[maxLength]; System.arraycopy(ptr.get(), ptr.getOffset(), newBytes, 0, ptr.getLength()); Arrays.fill(newBytes, ptr.getLength(), maxLength, sortOrder == SortOrder.ASC ? StringUtil.SPACE_UTF8 : StringUtil.INVERTED_SPACE_UTF8); ptr.set(newBytes); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { BigDecimal result = null; for (int i=0; i<children.size(); i++) { Expression childExpr = children.get(i); if (!childExpr.evaluate(tuple, ptr)) { return false; if (ptr.getLength() == 0) { return true; throw new ValueTypeIncompatibleException(PDataType.DECIMAL, maxLength, scale); ptr.set(PDataType.DECIMAL.toBytes(result)); return true;
@Override protected int compare(Tuple t1, Tuple t2) { for (int i = 0; i < orderByColumns.size(); i++) { OrderByExpression order = orderByColumns.get(i); Expression orderExpr = order.getExpression(); boolean isNull1 = !orderExpr.evaluate(t1, ptr1) || ptr1.getLength() == 0; boolean isNull2 = !orderExpr.evaluate(t2, ptr2) || ptr2.getLength() == 0; if (isNull1 && isNull2) { continue; } else if (isNull1) { return order.isNullsLast() ? 1 : -1; } else if (isNull2) { return order.isNullsLast() ? -1 : 1; } int cmp = ptr1.compareTo(ptr2); if (cmp == 0) { continue; } return order.isAscending() ? cmp : -cmp; } return 0; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression childExpr = children.get(0); if(childExpr.evaluate(tuple, ptr)) { if (ptr.getLength()==0) { return true; } BigDecimal value = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder()); BigDecimal scaledValue = value.setScale(scale, getRoundingMode()); ptr.set(PDecimal.INSTANCE.toBytes(scaledValue)); return true; } return false; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { boolean evaluated = children.get(0).evaluate(tuple, ptr); if (evaluated && ptr.getLength() > 0) { return true; } if (evaluated || tuple.isImmutable()) { Expression secondChild = children.get(1); if (secondChild.evaluate(tuple, ptr)) { // Coerce the type of the second child to the type of the first child getDataType().coerceBytes(ptr, secondChild.getDataType(), secondChild.getSortOrder(), getSortOrder()); return true; } } return false; }
@Override public void pad(ImmutableBytesWritable ptr, Integer maxLength, SortOrder sortOrder) { if (ptr.getLength() >= maxLength) { return; } byte[] newBytes = new byte[maxLength]; System.arraycopy(ptr.get(), ptr.getOffset(), newBytes, 0, ptr.getLength()); if (sortOrder == SortOrder.DESC) { Arrays.fill(newBytes, ptr.getLength(), maxLength, QueryConstants.DESC_SEPARATOR_BYTE); } ptr.set(newBytes); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { BigDecimal result = null; for (int i=0; i<children.size(); i++) { Expression childExpr = children.get(i); if (!childExpr.evaluate(tuple, ptr)) { return false; if (ptr.getLength() == 0) { return true; throw new DataExceedsCapacityException(PDecimal.INSTANCE, maxLength, scale); ptr.set(PDecimal.INSTANCE.toBytes(result)); return true;
@Override public Expression visitLeave(StringConcatParseNode node, List<Expression> children) throws SQLException { final StringConcatExpression expression=new StringConcatExpression(children); for (int i = 0; i < children.size(); i++) { ParseNode childNode=node.getChildren().get(i); if(childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode,expression); } PDataType type=children.get(i).getDataType(); if(type==PDataType.VARBINARY){ throw new SQLExceptionInfo.Builder(SQLExceptionCode.TYPE_NOT_SUPPORTED_FOR_OPERATOR) .setMessage("Concatenation does not support "+ type +" in expression" + node).build().buildException(); } } ImmutableBytesWritable ptr = context.getTempPtr(); if (expression.isStateless()) { if (!expression.evaluate(null,ptr) || ptr.getLength() == 0) { return LiteralExpression.newConstant(null, expression.getDataType(), expression.isDeterministic()); } return LiteralExpression.newConstant(expression.getDataType().toObject(ptr), expression.getDataType(), expression.isDeterministic()); } return wrapGroupByExpression(expression); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (children.get(0).evaluate(tuple, ptr)) { if (ptr.getLength()==0) { return true; } SortOrder sortOrder = children.get(0).getSortOrder(); PDataType dataType = getDataType(); int nanos = dataType.getNanos(ptr, sortOrder); if(nanos >= HALF_OF_NANOS_IN_MILLI) { long timeMillis = dataType.getMillis(ptr, sortOrder); Timestamp roundedTs = new Timestamp(timeMillis + 1); byte[] byteValue = dataType.toBytes(roundedTs); ptr.set(byteValue); } return true; // for timestamp we only support rounding up the milliseconds. } return false; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression indexExpr = children.get(1); if (!indexExpr.evaluate(tuple, ptr)) { return false; } else if (ptr.getLength() == 0) { return true; } // Use Codec to prevent Integer object allocation int index = PInteger.INSTANCE.getCodec().decodeInt(ptr, indexExpr.getSortOrder()); if(index < 0) { throw new ParseException("Index cannot be negative :" + index); } Expression arrayExpr = children.get(0); return PArrayDataTypeDecoder.positionAtArrayElement(tuple, ptr, index, arrayExpr, getDataType(), getMaxLength()); }
private void writeResult(ImmutableBytesWritable key, Result result, Context context) throws IOException, InterruptedException { Put put = null; Delete delete = null; if (LOG.isTraceEnabled()) { LOG.trace("Considering the row." + Bytes.toString(key.get(), key.getOffset(), key.getLength())); } if (filter == null || !filter.filterRowKey(PrivateCellUtil.createFirstOnRow(key.get(), key.getOffset(), (short) key.getLength()))) { processKV(key, result, context, put, delete); } }
BigDecimal finalResult = BigDecimal.ZERO; for(int i=0; i<children.size(); i++) { if (!children.get(i).evaluate(tuple, ptr)) { return false; if (ptr.getLength() == 0) { return true; PDataType type = children.get(i).getDataType(); SortOrder sortOrder = children.get(i).getSortOrder(); if(type == PTimestamp.INSTANCE || type == PUnsignedTimestamp.INSTANCE) { value = (BigDecimal)(PDecimal.INSTANCE.toObject(ptr, type, sortOrder)); byte[] resultPtr = new byte[getDataType().getByteSize()]; PTimestamp.INSTANCE.toBytes(ts, resultPtr, 0); ptr.set(resultPtr); return true;