Java Code Examples for org.apache.calcite.sql.SqlKind#COUNT

The following examples show how to use org.apache.calcite.sql.SqlKind#COUNT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComplexMetric.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if and only if this <code>ComplexMetric</code>
 * can be used in the given {@link AggregateCall}.
 * */
public boolean canBeUsed(AggregateCall call) {
  switch (type) {
  case HYPER_UNIQUE:
  case THETA_SKETCH:
    return call != null
          && call.getAggregation().getKind() == SqlKind.COUNT
          && call.isDistinct();
  default:
    return false;
  }
}
 
Example 2
Source File: SqlCountAggFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlCountAggFunction(String name,
    SqlOperandTypeChecker sqlOperandTypeChecker) {
  super(name, null, SqlKind.COUNT, ReturnTypes.BIGINT, null,
      sqlOperandTypeChecker, SqlFunctionCategory.NUMERIC, false, false,
      Optionality.FORBIDDEN);
}
 
Example 3
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static boolean isAggregation(SqlKind kind) {
	return kind == SqlKind.SUM || kind == SqlKind.SUM0
		|| kind == SqlKind.AVG || kind == SqlKind.COUNT
		|| kind == SqlKind.MAX || kind == SqlKind.MIN;
}
 
Example 4
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override public Set<String> visit(SqlCall call) {
	boolean isSingle = false;
	Set<String> vars = new HashSet<>();
	SqlKind kind = call.getKind();
	List<SqlNode> operands = call.getOperandList();

	if (isSingleVarRequired(kind)) {
		isSingle = true;
		if (isPhysicalNavigation(kind)) {
			if (isMeasure) {
				throw newValidationError(call,
					Static.RESOURCE.patternPrevFunctionInMeasure(call.toString()));
			}
			if (firstLastCount != 0) {
				throw newValidationError(call,
					Static.RESOURCE.patternPrevFunctionOrder(call.toString()));
			}
			prevNextCount++;
		} else if (isLogicalNavigation(kind)) {
			if (firstLastCount != 0) {
				throw newValidationError(call,
					Static.RESOURCE.patternPrevFunctionOrder(call.toString()));
			}
			firstLastCount++;
		} else if (isAggregation(kind)) {
			// cannot apply aggregation in PREV/NEXT, FIRST/LAST
			if (firstLastCount != 0 || prevNextCount != 0) {
				throw newValidationError(call,
					Static.RESOURCE.patternAggregationInNavigation(call.toString()));
			}
			if (kind == SqlKind.COUNT && call.getOperandList().size() > 1) {
				throw newValidationError(call,
					Static.RESOURCE.patternCountFunctionArg());
			}
			aggregateCount++;
		}
	}

	if (isRunningOrFinal(kind) && !isMeasure) {
		throw newValidationError(call,
			Static.RESOURCE.patternRunningFunctionInDefine(call.toString()));
	}

	for (SqlNode node : operands) {
		if (node != null) {
			vars.addAll(
				node.accept(
					new PatternValidator(isMeasure, firstLastCount, prevNextCount,
						aggregateCount)));
		}
	}

	if (isSingle) {
		switch (kind) {
			case COUNT:
				if (vars.size() > 1) {
					throw newValidationError(call,
						Static.RESOURCE.patternCountFunctionArg());
				}
				break;
			default:
				if (operands.size() == 0
					|| !(operands.get(0) instanceof SqlCall)
					|| ((SqlCall) operands.get(0)).getOperator() != SqlStdOperatorTable.CLASSIFIER) {
					if (vars.isEmpty()) {
						throw newValidationError(call,
							Static.RESOURCE.patternFunctionNullCheck(call.toString()));
					}
					if (vars.size() != 1) {
						throw newValidationError(call,
							Static.RESOURCE.patternFunctionVariableCheck(call.toString()));
					}
				}
				break;
		}
	}
	return vars;
}
 
Example 5
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
private static boolean isAggregation(SqlKind kind) {
	return kind == SqlKind.SUM || kind == SqlKind.SUM0
		|| kind == SqlKind.AVG || kind == SqlKind.COUNT
		|| kind == SqlKind.MAX || kind == SqlKind.MIN;
}
 
Example 6
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override public Set<String> visit(SqlCall call) {
	boolean isSingle = false;
	Set<String> vars = new HashSet<>();
	SqlKind kind = call.getKind();
	List<SqlNode> operands = call.getOperandList();

	if (isSingleVarRequired(kind)) {
		isSingle = true;
		if (isPhysicalNavigation(kind)) {
			if (isMeasure) {
				throw newValidationError(call,
					Static.RESOURCE.patternPrevFunctionInMeasure(call.toString()));
			}
			if (firstLastCount != 0) {
				throw newValidationError(call,
					Static.RESOURCE.patternPrevFunctionOrder(call.toString()));
			}
			prevNextCount++;
		} else if (isLogicalNavigation(kind)) {
			if (firstLastCount != 0) {
				throw newValidationError(call,
					Static.RESOURCE.patternPrevFunctionOrder(call.toString()));
			}
			firstLastCount++;
		} else if (isAggregation(kind)) {
			// cannot apply aggregation in PREV/NEXT, FIRST/LAST
			if (firstLastCount != 0 || prevNextCount != 0) {
				throw newValidationError(call,
					Static.RESOURCE.patternAggregationInNavigation(call.toString()));
			}
			if (kind == SqlKind.COUNT && call.getOperandList().size() > 1) {
				throw newValidationError(call,
					Static.RESOURCE.patternCountFunctionArg());
			}
			aggregateCount++;
		}
	}

	if (isRunningOrFinal(kind) && !isMeasure) {
		throw newValidationError(call,
			Static.RESOURCE.patternRunningFunctionInDefine(call.toString()));
	}

	for (SqlNode node : operands) {
		if (node != null) {
			vars.addAll(
				node.accept(
					new PatternValidator(isMeasure, firstLastCount, prevNextCount,
						aggregateCount)));
		}
	}

	if (isSingle) {
		switch (kind) {
			case COUNT:
				if (vars.size() > 1) {
					throw newValidationError(call,
						Static.RESOURCE.patternCountFunctionArg());
				}
				break;
			default:
				if (operands.size() == 0
					|| !(operands.get(0) instanceof SqlCall)
					|| ((SqlCall) operands.get(0)).getOperator() != SqlStdOperatorTable.CLASSIFIER) {
					if (vars.isEmpty()) {
						throw newValidationError(call,
							Static.RESOURCE.patternFunctionNullCheck(call.toString()));
					}
					if (vars.size() != 1) {
						throw newValidationError(call,
							Static.RESOURCE.patternFunctionVariableCheck(call.toString()));
					}
				}
				break;
		}
	}
	return vars;
}
 
Example 7
Source File: GlobalDictionaryVisitor.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private boolean needsValue(SqlKind sqlKind) {
  return SqlKind.COUNT != sqlKind;
}
 
Example 8
Source File: DruidTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
private boolean isCountDistinct(SqlCall call) {
  return call.getKind() == SqlKind.COUNT
          && call.getFunctionQuantifier() != null
          && call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT;
}
 
Example 9
Source File: SqlCountAggFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlCountAggFunction(String name,
    SqlOperandTypeChecker sqlOperandTypeChecker) {
  super(name, null, SqlKind.COUNT, ReturnTypes.BIGINT, null,
      sqlOperandTypeChecker, SqlFunctionCategory.NUMERIC, false, false,
      Optionality.FORBIDDEN);
}