use of org.voltdb.expressions.FunctionExpression in project voltdb by VoltDB.
the class AbstractParsedStmt method parseFunctionExpression.
/**
*
* @param paramsById
* @param exprNode
* @return a new Function Expression
*/
private AbstractExpression parseFunctionExpression(VoltXMLElement exprNode) {
String name = exprNode.attributes.get("name").toLowerCase();
String disabled = exprNode.attributes.get("disabled");
if (disabled != null) {
throw new PlanningErrorException("Function '" + name + "' is not supported in VoltDB: " + disabled);
}
String value_type_name = exprNode.attributes.get("valuetype");
VoltType value_type = VoltType.typeFromString(value_type_name);
String function_id = exprNode.attributes.get("function_id");
assert (function_id != null);
int idArg = 0;
try {
idArg = Integer.parseInt(function_id);
} catch (NumberFormatException nfe) {
}
assert (idArg > 0);
String result_type_parameter_index = exprNode.attributes.get("result_type_parameter_index");
String implied_argument = exprNode.attributes.get("implied_argument");
ArrayList<AbstractExpression> args = new ArrayList<>();
for (VoltXMLElement argNode : exprNode.children) {
assert (argNode != null);
// recursively parse each argument subtree (could be any kind of expression).
AbstractExpression argExpr = parseExpressionNode(argNode);
assert (argExpr != null);
args.add(argExpr);
}
FunctionExpression expr = new FunctionExpression();
expr.setAttributes(name, implied_argument, idArg);
expr.setArgs(args);
if (value_type != null) {
expr.setValueType(value_type);
if (value_type != VoltType.INVALID && value_type != VoltType.NUMERIC) {
int size = value_type.getMaxLengthInBytes();
expr.setValueSize(size);
}
}
if (result_type_parameter_index != null) {
int parameter_idx = -1;
try {
parameter_idx = Integer.parseInt(result_type_parameter_index);
} catch (NumberFormatException nfe) {
}
// better be valid by now.
assert (parameter_idx >= 0);
// must refer to a provided argument
assert (parameter_idx < args.size());
expr.setResultTypeParameterIndex(parameter_idx);
expr.negotiateInitialValueTypes();
}
return expr;
}
use of org.voltdb.expressions.FunctionExpression in project voltdb by VoltDB.
the class ParsedInsertStmt method defaultValueToExpr.
private AbstractExpression defaultValueToExpr(Column column) {
AbstractExpression expr = null;
boolean isConstantValue = true;
if (column.getDefaulttype() == VoltType.TIMESTAMP.getValue()) {
boolean isFunctionFormat = true;
String timeValue = column.getDefaultvalue();
try {
Long.parseLong(timeValue);
isFunctionFormat = false;
} catch (NumberFormatException e) {
}
if (isFunctionFormat) {
try {
java.sql.Timestamp.valueOf(timeValue);
isFunctionFormat = false;
} catch (IllegalArgumentException e) {
}
}
if (isFunctionFormat) {
String name = timeValue.split(":")[0];
int id = Integer.parseInt(timeValue.split(":")[1]);
FunctionExpression funcExpr = new FunctionExpression();
funcExpr.setAttributes(name, null, id);
funcExpr.setValueType(VoltType.TIMESTAMP);
funcExpr.setValueSize(VoltType.TIMESTAMP.getMaxLengthInBytes());
expr = funcExpr;
isConstantValue = false;
}
}
if (isConstantValue) {
// Not Default sql function.
ConstantValueExpression const_expr = new ConstantValueExpression();
expr = const_expr;
if (column.getDefaulttype() != 0) {
const_expr.setValue(column.getDefaultvalue());
const_expr.refineValueType(VoltType.get((byte) column.getDefaulttype()), column.getSize());
} else {
const_expr.setValue(null);
const_expr.refineValueType(VoltType.get((byte) column.getType()), column.getSize());
}
}
assert (expr != null);
return expr;
}
use of org.voltdb.expressions.FunctionExpression in project voltdb by VoltDB.
the class SubPlanAssembler method getRelevantAccessPathForGeoIndex.
private AccessPath getRelevantAccessPathForGeoIndex(AccessPath retval, StmtTableScan tableScan, List<AbstractExpression> indexedExprs, List<ColumnRef> indexedColRefs, List<AbstractExpression> filtersToCover) {
// geo expressions not yet supported
assert indexedExprs == null;
// for now a geo COLUMN is required.
assert indexedColRefs != null;
assert isAGeoColumnIndex(indexedColRefs);
Column geoCol = indexedColRefs.get(0).getColumn();
// Match only the table's column that has the coveringColId
// Handle a simple indexed column identified by its column id.
int coveringColId = geoCol.getIndex();
String tableAlias = tableScan.getTableAlias();
// we change FunctionForVoltDB to support APPROX_CONTAINS.
for (AbstractExpression filter : filtersToCover) {
if (filter.getExpressionType() != ExpressionType.FUNCTION) {
continue;
}
if (filter.getValueType() != VoltType.BOOLEAN) {
continue;
}
List<AbstractExpression> args = filter.getArgs();
if (args.size() != 2) {
continue;
}
FunctionExpression fn = (FunctionExpression) filter;
//TODO: also support explicit APPROX_CONTAINS
if (!fn.hasFunctionId(FunctionForVoltDB.FUNC_VOLT_ID_FOR_CONTAINS)) {
continue;
}
AbstractExpression indexableArg = args.get(0);
assert indexableArg instanceof TupleValueExpression;
assert indexableArg.getValueType() == VoltType.GEOGRAPHY;
TupleValueExpression geoTve = (TupleValueExpression) indexableArg;
if (!tableAlias.equals(geoTve.getTableAlias())) {
continue;
}
if (coveringColId != geoTve.getColumnIndex()) {
continue;
}
AbstractExpression searchKeyArg = args.get(1);
assert searchKeyArg.getValueType() == VoltType.GEOGRAPHY_POINT;
// e.g. contains(t.a, t.b) is not indexable.
if (isOperandDependentOnTable(searchKeyArg, tableScan)) {
continue;
}
filtersToCover.remove(searchKeyArg);
retval.indexExprs.add(searchKeyArg);
retval.otherExprs.addAll(filtersToCover);
retval.lookupType = IndexLookupType.GEO_CONTAINS;
// "WHERE int_key > 30 AND int_key > ?".
return retval;
}
return null;
}
Aggregations