private void initialize() { if(children.size() > 1) { String localeISOCode = getLiteralValue(1, String.class); locale = LocaleUtils.get().getLocaleByIsoCode(localeISOCode); } }
@Override public PDataType getDataType() { return getStrExpression().getDataType(); }
public LowerFunction(List<Expression> children) throws SQLException { super(children); initialize(); }
@Test public void lower() throws Exception { List<Expression> args = Lists.newArrayList(getInvertedLiteral("BLAH", PChar.INSTANCE)); evaluateAndAssertResult(new LowerFunction(args), "blah"); }
private static String callFunction(String inputStr, String localeIsoCode, SortOrder sortOrder) throws Exception { LiteralExpression inputStrLiteral, localeIsoCodeLiteral; inputStrLiteral = LiteralExpression.newConstant(inputStr, PVarchar.INSTANCE, sortOrder); localeIsoCodeLiteral = LiteralExpression.newConstant(localeIsoCode, PVarchar.INSTANCE, sortOrder); List<Expression> expressions = Lists.newArrayList((Expression) inputStrLiteral, (Expression) localeIsoCodeLiteral); Expression lowerFunction = new LowerFunction(expressions); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); boolean ret = lowerFunction.evaluate(null, ptr); String result = ret ? (String) lowerFunction.getDataType().toObject(ptr, lowerFunction.getSortOrder()) : null; return result; } }
@Override public boolean isNullable() { return getStrExpression().isNullable(); }
@Override public void readFields(DataInput input) throws IOException { super.readFields(input); initialize(); }
private void initialize() { if(children.size() > 1) { String localeISOCode = getLiteralValue(1, String.class); locale = LocaleUtils.get().getLocaleByIsoCode(localeISOCode); } }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getStrExpression().evaluate(tuple, ptr)) { return false; } if (ptr.getLength()==0) { return true; } String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, getStrExpression().getSortOrder()); if (sourceStr == null) { return true; } String resultStr = locale == null ? sourceStr.toLowerCase() : sourceStr.toLowerCase(locale); ptr.set(PVarchar.INSTANCE.toBytes(resultStr)); return true; }
public LowerFunction(List<Expression> children) throws SQLException { super(children); initialize(); }
private void initialize() { if(children.size() > 1) { String localeISOCode = getLiteralValue(1, String.class); locale = LocaleUtils.get().getLocaleByIsoCode(localeISOCode); } }
@Override public boolean isNullable() { return getStrExpression().isNullable(); }
public LowerFunction(List<Expression> children) throws SQLException { super(children); initialize(); }
@Override public PDataType getDataType() { return getStrExpression().getDataType(); }
@Override public void readFields(DataInput input) throws IOException { super.readFields(input); initialize(); }
@Override public boolean isNullable() { return getStrExpression().isNullable(); }
@Override public void readFields(DataInput input) throws IOException { super.readFields(input); initialize(); }
@Override public PDataType getDataType() { return getStrExpression().getDataType(); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getStrExpression().evaluate(tuple, ptr)) { return false; } if (ptr.getLength()==0) { return true; } String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, getStrExpression().getSortOrder()); if (sourceStr == null) { return true; } String resultStr = locale == null ? sourceStr.toLowerCase() : sourceStr.toLowerCase(locale); ptr.set(PVarchar.INSTANCE.toBytes(resultStr)); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getStrExpression().evaluate(tuple, ptr)) { return false; } if (ptr.getLength()==0) { return true; } String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, getStrExpression().getSortOrder()); if (sourceStr == null) { return true; } String resultStr = locale == null ? sourceStr.toLowerCase() : sourceStr.toLowerCase(locale); ptr.set(PVarchar.INSTANCE.toBytes(resultStr)); return true; }