@Override public ExprNodeDesc clone() { return new ExprNodeConstantDesc(typeInfo, value); }
public static boolean isNullConstant(ExprNodeDesc value) { if ((value instanceof ExprNodeConstantDesc) && ((ExprNodeConstantDesc) value).getValue() == null) { return true; } return false; }
private Object getScalarValue(ExprNodeConstantDesc constDesc) throws HiveException { if (constDesc.getTypeString().equalsIgnoreCase("String")) { try { byte[] bytes = ((String) constDesc.getValue()).getBytes("UTF-8"); return bytes; } catch (Exception ex) { throw new HiveException(ex); } } else if (constDesc.getTypeString().equalsIgnoreCase("boolean")) { if (constDesc.getValue().equals(Boolean.valueOf(true))) { return 1; } else { return 0; } } else if (decimalTypePattern.matcher(constDesc.getTypeString()).matches()) { return constDesc.getValue(); } else { return constDesc.getValue(); } }
@Override public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs) throws SemanticException { if (nd instanceof ExprNodeConstantDesc) { return ((ExprNodeConstantDesc) nd).clone(); } return new ExprNodeConstantDesc(((ExprNodeDesc)nd).getTypeInfo(), null); } }
@Override public boolean isSame(Object o) { if (!(o instanceof ExprNodeConstantDesc)) { return false; } ExprNodeConstantDesc dest = (ExprNodeConstantDesc) o; if (!typeInfo.equals(dest.getTypeInfo())) { return false; } if (value == null) { if (dest.getValue() != null) { return false; } } else if (!value.equals(dest.getValue())) { return false; } return true; }
ExprNodeConstantDesc valExpr = (ExprNodeConstantDesc)TypeCheckProcFactory .genExprNode(partValNode, typeCheckCtx).get(partValNode); Object val = valExpr.getValue(); if (!valExpr.getTypeString().equals(type)) { Converter converter = ObjectInspectorConverters.getConverter( TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(valExpr.getTypeInfo()), TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(pti)); val = converter.convert(valExpr.getValue()); ExprNodeGenericFuncDesc op; if (!isDefaultPartitionName) { op = makeBinaryPredicate(operator, column, new ExprNodeConstantDesc(pti, val)); } else { GenericUDF originalOp = FunctionRegistry.getFunctionInfo(operator).getGenericUDF();
if (desc instanceof ExprNodeConstantDesc) { ExprNodeConstantDesc constant = (ExprNodeConstantDesc) exprs.get(i); if (!constant.getTypeInfo().equals(oldExprs.get(i).getTypeInfo())) { constant = typeCast(constant, oldExprs.get(i).getTypeInfo()); if (constant == null) { if (constant.getTypeInfo().getCategory() != Category.PRIMITIVE) { Object value = constant.getValue(); PrimitiveTypeInfo pti = (PrimitiveTypeInfo) constant.getTypeInfo(); Object writableValue = null == value ? value : PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pti) arguments[i] = new DeferredJavaObject(writableValue); argois[i] = ObjectInspectorUtils.getConstantObjectInspector(constant.getWritableObjectInspector(), writableValue); if (constant.getTypeInfo().getCategory() != Category.PRIMITIVE) { (PrimitiveTypeInfo) constant.getTypeInfo()).getPrimitiveWritableObject(constant.getValue()); arguments[i] = new DeferredJavaObject(writableValue); argois[i] = ObjectInspectorUtils.getConstantObjectInspector(constant.getWritableObjectInspector(), writableValue); } else { return null; return new ExprNodeConstantDesc( TypeInfoUtils.getTypeInfoFromObjectInspector(oi), o);
private static List<ExprNodeDesc> asListOfNodes(ExprNodeDesc desc) { ExprNodeDesc valueDesc = desc; if (ExprNodeDescUtils.isStructUDF(desc)) { List<ExprNodeDesc> valueChilds = ((ExprNodeGenericFuncDesc) valueDesc).getChildren(); for (ExprNodeDesc exprNodeDesc : valueChilds) { if (!isSafeExpression(exprNodeDesc)) { return null; } } return valueChilds; } if (ExprNodeDescUtils.isConstantStruct(valueDesc)) { ExprNodeConstantDesc valueConstDesc = (ExprNodeConstantDesc) valueDesc; List<Object> oldValues = (List<Object>) valueConstDesc.getValue(); StructTypeInfo structTypeInfo = (StructTypeInfo) valueConstDesc.getTypeInfo(); ArrayList<TypeInfo> structFieldInfos = structTypeInfo.getAllStructFieldTypeInfos(); List<ExprNodeDesc> ret = new ArrayList<>(); for (int i = 0; i < oldValues.size(); i++) { ret.add(new ExprNodeConstantDesc(structFieldInfos.get(i), oldValues.get(i))); } return ret; } if (isSafeExpression(desc)) { return Lists.newArrayList(desc); } return null; }
private static ExprNodeConstantDesc toListConstDesc(ColumnInfo colInfo, ObjectInspector inspector, ObjectInspector listElementOI) { PrimitiveObjectInspector poi = (PrimitiveObjectInspector)listElementOI; List<?> values = (List<?>)((ConstantObjectInspector) inspector).getWritableConstantValue(); List<Object> constant = new ArrayList<Object>(); for (Object o : values) { constant.add(poi.getPrimitiveJavaObject(o)); } ExprNodeConstantDesc constantExpr = new ExprNodeConstantDesc(colInfo.getType(), constant); constantExpr.setFoldedFromCol(colInfo.getInternalName()); return constantExpr; }
colName = encd.getName(); colType = encd.getTypeString(); if (encd.getValue() == null) {
List<?> items = (List<?>) constantChild.getWritableObjectInspector().getWritableConstantValue(); List<TypeInfo> structTypes = ((StructTypeInfo) constantChild.getTypeInfo()).getAllStructFieldTypeInfos(); for (int j = 0; j < structTypes.size(); j++) { ExprNodeConstantDesc constant = new ExprNodeConstantDesc(structTypes.get(j), items.get(j)); values.get(j).add(new ExprNodeDescEqualityWrapper(constant));
private static ExprNodeDesc interpretNodeAs(PrimitiveTypeInfo colTypeInfo, ExprNodeDesc constChild) { if (constChild instanceof ExprNodeConstantDesc) { // Try to narrow type of constant Object constVal = ((ExprNodeConstantDesc) constChild).getValue(); if (constVal == null) { // adjust type of null return new ExprNodeConstantDesc(colTypeInfo, null); } Object newConst = interpretConstantAsPrimitive(colTypeInfo, constVal, constChild.getTypeInfo()); if (newConst == null) { return null; } if(newConst == constVal) { return constChild; } else { return new ExprNodeConstantDesc(adjustType(colTypeInfo, newConst), newConst); } } return constChild; }
} catch (ClassCastException cce) { throw new IOException("Currently only primitve types are supported. Found: " + sc.getConstantDesc().getTypeString()); } catch (HiveException e) { throw new IOException(e);
ObjectInspector childoi = foldedChild.getWritableObjectInspector(); GenericUDF gudf = ((ExprNodeGenericFuncDesc) exprDesc).getGenericUDF(); Object constant = evaluator.evaluate(null); Object java = ObjectInspectorUtils.copyToStandardJavaObject(constant, output); return new ExprNodeConstantDesc(exprDesc.getTypeInfo(), java);
LOG.debug("Filter " + udf + " is identified as a value assignment, propagate it."); if (!v.getTypeInfo().equals(ci.getType())) { v = typeCast(v, ci.getType(), true); ColumnInfo ci = resolveColumn(rs, c); if (ci != null) { constants.put(ci, new ExprNodeConstantDesc(ci.getType(), null));
protected RexNode convert(ExprNodeConstantDesc literal) throws CalciteSemanticException { RexBuilder rexBuilder = cluster.getRexBuilder(); RelDataTypeFactory dtFactory = rexBuilder.getTypeFactory(); PrimitiveTypeInfo hiveType = (PrimitiveTypeInfo) literal.getTypeInfo(); RelDataType calciteDataType = TypeConverter.convert(hiveType, dtFactory); ConstantObjectInspector coi = literal.getWritableObjectInspector(); Object value = ObjectInspectorUtils.copyToStandardJavaObject(coi.getWritableConstantValue(), coi); throw new CalciteSemanticException("Expression " + literal.getExprString() + " is not a valid decimal", UnsupportedFeature.Invalid_decimal);
static private boolean isBooleanExpr(ExprNodeDesc expr) { return expr != null && expr instanceof ExprNodeConstantDesc && ((ExprNodeConstantDesc)expr).getTypeInfo() instanceof PrimitiveTypeInfo && ((PrimitiveTypeInfo)(((ExprNodeConstantDesc)expr).getTypeInfo())). getTypeName().equals(serdeConstants.BOOLEAN_TYPE_NAME); } static private boolean isTrueExpr(ExprNodeDesc expr) {
@Override /** * Return string representation of constant expression * Beside ExplainPlan task Default constraint also make use it to deserialize constant expression * to store it in metastore, which is later reparsed to generate appropriate constant expression * Therefore it is necessary for this method to qualify the intervals with appropriate qualifiers */ public String getExprString() { if (typeInfo.getCategory() == Category.PRIMITIVE) { return getFormatted(typeInfo, value); } else if (typeInfo.getCategory() == Category.STRUCT) { StringBuilder sb = new StringBuilder(); sb.append("const struct("); List<?> items = (List<?>) getWritableObjectInspector().getWritableConstantValue(); List<TypeInfo> structTypes = ((StructTypeInfo) typeInfo).getAllStructFieldTypeInfos(); for (int i = 0; i < structTypes.size(); i++) { final Object o = (i < items.size()) ? items.get(i) : null; sb.append(getFormatted(structTypes.get(i), o)).append(","); } sb.setCharAt(sb.length() - 1, ')'); return sb.toString(); } else { // unknown type return toString(); } }
if (HiveConf.getPositionFromInternalName(colName) == -1) { ((ExprNodeConstantDesc)newCol).setFoldedFromCol(colName); } else { ((ExprNodeConstantDesc)newCol).setFoldedFromCol(((ExprNodeConstantDesc)desc).getFoldedFromCol());
public ExprNodeConstantEvaluator(ExprNodeConstantDesc expr, Configuration conf) { super(expr, conf); writableObjectInspector = expr.getWritableObjectInspector(); }