本文整理汇总了Java中org.apache.calcite.sql.SqlCall.operand方法的典型用法代码示例。如果您正苦于以下问题:Java SqlCall.operand方法的具体用法?Java SqlCall.operand怎么用?Java SqlCall.operand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.sql.SqlCall
的用法示例。
在下文中一共展示了SqlCall.operand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AggConverter
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
/**
* Creates an AggConverter.
*
* <p>The <code>select</code> parameter provides enough context to name
* aggregate calls which are top-level select list items.
*
* @param bb Blackboard
* @param select Query being translated; provides context to give
*/
public AggConverter(Blackboard bb, SqlSelect select) {
this.bb = bb;
this.aggregatingSelectScope =
(AggregatingSelectScope) bb.getValidator().getSelectScope(select);
// Collect all expressions used in the select list so that aggregate
// calls can be named correctly.
final SqlNodeList selectList = select.getSelectList();
for (int i = 0; i < selectList.size(); i++) {
SqlNode selectItem = selectList.get(i);
String name = null;
if (SqlUtil.isCallTo(
selectItem,
SqlStdOperatorTable.AS)) {
final SqlCall call = (SqlCall) selectItem;
selectItem = call.operand(0);
name = call.operand(1).toString();
}
if (name == null) {
name = validator.deriveAlias(selectItem, i);
}
nameMap.put(selectItem.toString(), name);
}
}
示例2: AggConverter
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
/**
* Creates an AggConverter.
*
* <p>The <code>select</code> parameter provides enough context to name
* aggregate calls which are top-level select list items.
*
* @param bb Blackboard
* @param select Query being translated; provides context to give
*/
public AggConverter(Blackboard bb, SqlSelect select) {
this.bb = bb;
this.aggregatingSelectScope =
(AggregatingSelectScope) bb.getValidator().getSelectScope(select);
// Collect all expressions used in the select list so that aggregate
// calls can be named correctly.
final SqlNodeList selectList = select.getSelectList();
for (int i = 0; i < selectList.size(); i++) {
SqlNode selectItem = selectList.get(i);
String name = null;
if (SqlUtil.isCallTo(
selectItem,
SqlStdOperatorTable.AS)) {
final SqlCall call = (SqlCall) selectItem;
selectItem = call.operand(0);
name = call.operand(1).toString();
}
if (name == null) {
name = validator.deriveAlias(selectItem, i);
}
nameMap.put(selectItem.toString(), name);
}
}
示例3: registerOperandSubQueries
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
/**
* Registers any sub-queries inside a given call operand, and converts the
* operand to a scalar sub-query if the operator requires it.
*
* @param parentScope Parent scope
* @param call Call
* @param operandOrdinal Ordinal of operand within call
* @see SqlOperator#argumentMustBeScalar(int)
*/
private void registerOperandSubQueries(
SqlValidatorScope parentScope,
SqlCall call,
int operandOrdinal) {
SqlNode operand = call.operand(operandOrdinal);
if (operand == null) {
return;
}
if (operand.getKind().belongsTo(SqlKind.QUERY)
&& call.getOperator().argumentMustBeScalar(operandOrdinal)) {
operand =
SqlStdOperatorTable.SCALAR_QUERY.createCall(
operand.getParserPosition(),
operand);
call.setOperand(operandOrdinal, operand);
}
registerSubQueries(parentScope, operand);
}
示例4: unparseCall
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
if (call.getOperator() == SqlStdOperatorTable.SUBSTRING) {
SqlUtil.unparseFunctionSyntax(OracleSqlOperatorTable.SUBSTR, writer, call);
} else {
switch (call.getKind()) {
case FLOOR:
if (call.operandCount() != 2) {
super.unparseCall(writer, call, leftPrec, rightPrec);
return;
}
final SqlLiteral timeUnitNode = call.operand(1);
final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);
SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, timeUnit.name(),
timeUnitNode.getParserPosition());
SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
break;
default:
super.unparseCall(writer, call, leftPrec, rightPrec);
}
}
}
示例5: unparseCall
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
switch (call.getKind()) {
case FLOOR:
if (call.operandCount() != 2) {
super.unparseCall(writer, call, leftPrec, rightPrec);
return;
}
final SqlLiteral timeUnitNode = call.operand(1);
final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);
final String translatedLit = convertTimeUnit(timeUnit);
SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, translatedLit,
timeUnitNode.getParserPosition());
SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
break;
default:
super.unparseCall(writer, call, leftPrec, rightPrec);
}
}
示例6: unparseCall
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
switch (call.getKind()) {
case FLOOR:
if (call.operandCount() != 2) {
super.unparseCall(writer, call, leftPrec, rightPrec);
return;
}
final SqlLiteral timeUnitNode = call.operand(1);
final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);
SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, timeUnit.name(),
timeUnitNode.getParserPosition());
SqlFloorFunction.unparseDatetimeFunction(writer, call2, "DATE_TRUNC", false);
break;
default:
super.unparseCall(writer, call, leftPrec, rightPrec);
}
}
示例7: unparseDatetimeFunction
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
/**
* Most dialects that natively support datetime floor will use this.
* In those cases the call will look like TRUNC(datetime, 'year').
*
* @param writer SqlWriter
* @param call SqlCall
* @param funName Name of the sql function to call
* @param datetimeFirst Specify the order of the datetime & timeUnit
* arguments
*/
public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call,
String funName, Boolean datetimeFirst) {
SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION,
ReturnTypes.ARG0_NULLABLE_VARYING, null, null,
SqlFunctionCategory.STRING);
SqlCall call1;
if (datetimeFirst) {
call1 = call;
} else {
// switch order of operands
SqlNode op1 = call.operand(0);
SqlNode op2 = call.operand(1);
call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1);
}
SqlUtil.unparseFunctionSyntax(func, writer, call1);
}
示例8: assertExprPrintsTo
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
protected void assertExprPrintsTo(
boolean newlines,
final String sql,
String expected) {
final SqlCall valuesCall = (SqlCall) parseQuery("VALUES (" + sql + ")");
final SqlCall rowCall = valuesCall.operand(0);
final SqlNode node = rowCall.operand(0);
final SqlPrettyWriter prettyWriter =
new SqlPrettyWriter(AnsiSqlDialect.DEFAULT);
prettyWriter.setAlwaysUseParentheses(false);
if (newlines) {
prettyWriter.setCaseClausesOnNewLines(true);
}
String actual = prettyWriter.format(node);
getDiffRepos().assertEquals("formatted", expected, actual);
// Now parse the result, and make sure it is structurally equivalent
// to the original.
final String actual2 = actual.replaceAll("`", "\"");
final SqlNode valuesCall2 = parseQuery("VALUES (" + actual2 + ")");
assertTrue(valuesCall.equalsDeep(valuesCall2, Litmus.THROW));
}
示例9: unparse
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
@Override public void unparse(SqlWriter writer, SqlCall call,
int leftPrec, int rightPrec) {
call.operand(0).unparse(writer, this.getLeftPrec(), this.getRightPrec());
int startNum = ((SqlNumericLiteral) call.operand(1)).intValue(true);
SqlNumericLiteral endRepNum = call.operand(2);
boolean isReluctant = ((SqlLiteral) call.operand(3)).booleanValue();
int endNum = endRepNum.intValue(true);
if (startNum == endNum) {
writer.keyword("{ " + startNum + " }");
} else {
if (endNum == -1) {
if (startNum == 0) {
writer.keyword("*");
} else if (startNum == 1) {
writer.keyword("+");
} else {
writer.keyword("{ " + startNum + ", }");
}
} else {
if (startNum == 0 && endNum == 1) {
writer.keyword("?");
} else if (startNum == -1) {
writer.keyword("{ , " + endNum + " }");
} else {
writer.keyword("{ " + startNum + ", " + endNum + " }");
}
}
if (isReluctant) {
writer.keyword("?");
}
}
}
示例10: isSimpleCount
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
private boolean isSimpleCount(SqlCall call) {
if (call.getOperator().isName("COUNT") && call.operandCount() == 1) {
final SqlNode parm = call.operand(0);
if ((parm instanceof SqlIdentifier || parm instanceof SqlNumericLiteral) //
&& call.getFunctionQuantifier() == null) {
return true;
}
}
return false;
}
示例11: convertFloorCeil
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
protected RexNode convertFloorCeil(SqlRexContext cx, SqlCall call) {
final boolean floor = call.getKind() == SqlKind.FLOOR;
// Rewrite floor, ceil of interval
if (call.operandCount() == 1
&& call.operand(0) instanceof SqlIntervalLiteral) {
final SqlIntervalLiteral literal = call.operand(0);
SqlIntervalLiteral.IntervalValue interval =
(SqlIntervalLiteral.IntervalValue) literal.getValue();
BigDecimal val =
interval.getIntervalQualifier().getStartUnit().multiplier;
RexNode rexInterval = cx.convertExpression(literal);
final RexBuilder rexBuilder = cx.getRexBuilder();
RexNode zero = rexBuilder.makeExactLiteral(BigDecimal.valueOf(0));
RexNode cond = ge(rexBuilder, rexInterval, zero);
RexNode pad =
rexBuilder.makeExactLiteral(val.subtract(BigDecimal.ONE));
RexNode cast = rexBuilder.makeReinterpretCast(
rexInterval.getType(), pad, rexBuilder.makeLiteral(false));
RexNode sum = floor
? minus(rexBuilder, rexInterval, cast)
: plus(rexBuilder, rexInterval, cast);
RexNode kase = floor
? case_(rexBuilder, rexInterval, cond, sum)
: case_(rexBuilder, sum, cond, rexInterval);
RexNode factor = rexBuilder.makeExactLiteral(val);
RexNode div = divideInt(rexBuilder, kase, factor);
return multiply(rexBuilder, div, factor);
}
// normal floor, ceil function
return convertFunction(cx, (SqlFunction) call.getOperator(), call);
}
示例12: convertCall
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
// TIMESTAMPADD(unit, count, timestamp)
// => timestamp + count * INTERVAL '1' UNIT
final RexBuilder rexBuilder = cx.getRexBuilder();
final SqlLiteral unitLiteral = call.operand(0);
final TimeUnit unit = unitLiteral.symbolValue(TimeUnit.class);
return rexBuilder.makeCall(SqlStdOperatorTable.DATETIME_PLUS,
cx.convertExpression(call.operand(2)),
multiply(rexBuilder,
rexBuilder.makeIntervalLiteral(unit.multiplier,
new SqlIntervalQualifier(unit, null,
unitLiteral.getParserPosition())),
cx.convertExpression(call.operand(1))));
}
示例13: validateOver
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
protected void validateOver(SqlCall call, SqlValidatorScope scope) {
try {
final OverScope overScope = (OverScope) getOverScope(call);
final SqlNode relation = call.operand(0);
validateFrom(relation, unknownType, scope);
final SqlNode window = call.operand(1);
SqlValidatorScope opScope = scopes.get(relation);
if (opScope == null) {
opScope = overScope;
}
validateWindow(window, opScope, null);
} catch (CalciteException e) {
Util.swallow(e, TRACER);
}
}
示例14: unparseFloor
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
/**
* Unparses datetime floor for Microsoft SQL Server.
* There is no TRUNC function, so simulate this using calls to CONVERT.
*
* @param writer Writer
* @param call Call
*/
private void unparseFloor(SqlWriter writer, SqlCall call) {
SqlLiteral node = call.operand(1);
TimeUnitRange unit = (TimeUnitRange) node.getValue();
switch (unit) {
case YEAR:
unparseFloorWithUnit(writer, call, 4, "-01-01");
break;
case MONTH:
unparseFloorWithUnit(writer, call, 7, "-01");
break;
case WEEK:
writer.print("CONVERT(DATETIME, CONVERT(VARCHAR(10), "
+ "DATEADD(day, - (6 + DATEPART(weekday, ");
call.operand(0).unparse(writer, 0, 0);
writer.print(")) % 7, ");
call.operand(0).unparse(writer, 0, 0);
writer.print("), 126))");
break;
case DAY:
unparseFloorWithUnit(writer, call, 10, "");
break;
case HOUR:
unparseFloorWithUnit(writer, call, 13, ":00:00");
break;
case MINUTE:
unparseFloorWithUnit(writer, call, 16, ":00");
break;
case SECOND:
unparseFloorWithUnit(writer, call, 19, ":00");
break;
default:
throw new IllegalArgumentException("MSSQL does not support FLOOR for time unit: "
+ unit);
}
}
示例15: unparse
import org.apache.calcite.sql.SqlCall; //导入方法依赖的package包/类
public void unparse(
SqlWriter writer,
SqlCall call,
int leftPrec,
int rightPrec) {
final SqlWriter.Frame frame =
writer.startList(FRAME_TYPE, "", "");
call.operand(VALUE_OPERAND).unparse(writer, getLeftPrec(), 0);
writer.sep(super.getName());
writer.sep(flag.name());
// If the expression for the lower bound contains a call to an AND
// operator, we need to wrap the expression in parentheses to prevent
// the AND from associating with BETWEEN. For example, we should
// unparse
// a BETWEEN b OR (c AND d) OR e AND f
// as
// a BETWEEN (b OR c AND d) OR e) AND f
// If it were unparsed as
// a BETWEEN b OR c AND d OR e AND f
// then it would be interpreted as
// (a BETWEEN (b OR c) AND d) OR (e AND f)
// which would be wrong.
final SqlNode lower = call.operand(LOWER_OPERAND);
final SqlNode upper = call.operand(UPPER_OPERAND);
int lowerPrec = new AndFinder().containsAnd(lower) ? 100 : 0;
lower.unparse(writer, lowerPrec, lowerPrec);
writer.sep("AND");
upper.unparse(writer, 0, getRightPrec());
writer.endList(frame);
}