tkalkirill commented on code in PR #13311:
URL: https://github.com/apache/ignite/pull/13311#discussion_r3718726201
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java:
##########
@@ -241,54 +241,80 @@ private void validateTableModify(SqlNode table) {
/** {@inheritDoc} */
@Override protected void validateSelect(SqlSelect select, RelDataType
targetRowType) {
- checkIntegerLimit(select.getFetch(), "fetch / limit");
- checkIntegerLimit(select.getOffset(), "offset");
-
super.validateSelect(select, targetRowType);
- }
-
- /** {@inheritDoc} */
- @Override protected void validateNamespace(SqlValidatorNamespace
namespace, RelDataType targetRowType) {
- SqlValidatorTable table = namespace.getTable();
-
- if (table != null) {
- IgniteCacheTable igniteTable =
table.unwrap(IgniteCacheTable.class);
- if (igniteTable != null)
- igniteTable.ensureCacheStarted();
- }
-
- super.validateNamespace(namespace, targetRowType);
+ validateFetchOffset(select.getFetch(), "fetch / limit");
+ validateFetchOffset(select.getOffset(), "offset");
}
/**
- * @param n Node to check limit.
+ * Invalidate fetch/offset params restrictions.
+ *
+ * @param n Node to check limit.
* @param nodeName Node name.
*/
- private void checkIntegerLimit(SqlNode n, String nodeName) {
+ private void validateFetchOffset(@Nullable SqlNode n, String nodeName) {
+ if (n == null)
+ return;
+
if (n instanceof SqlLiteral) {
- BigDecimal offFetchLimit = ((SqlLiteral)n).bigDecimalValue();
+ BigDecimal offsetFetchLimit = ((SqlLiteral)n).bigDecimalValue();
- if (offFetchLimit.compareTo(DEC_INT_MAX) > 0 ||
offFetchLimit.compareTo(BigDecimal.ZERO) < 0)
- throw newValidationError(n,
IgniteResource.INSTANCE.correctIntegerLimit(nodeName));
+ checkLimitOffset(offsetFetchLimit, n, nodeName);
}
- else if (n instanceof SqlDynamicParam) {
- // will fail in params check.
+ else if (n instanceof SqlDynamicParam dynamicParam) {
if (F.isEmpty(parameters))
return;
- int idx = ((SqlDynamicParam)n).getIndex();
+ if (dynamicParam.getIndex() < parameters.length) {
+ Object param = parameters[dynamicParam.getIndex()];
+
+ if (!(param instanceof Number)) {
+ SqlTypeName expectType = SqlTypeName.BIGINT;
+ Resources.ExInst<SqlValidatorException> err;
+
+ if (param == null)
+ err =
IgniteResource.INSTANCE.incorrectDynamicParameterType(expectType.toString(),
"null");
+ else {
+ SqlTypeName paramType =
typeFactory().createType(param.getClass()).getSqlTypeName();
+ err =
IgniteResource.INSTANCE.incorrectDynamicParameterType(expectType.toString(),
paramType.getName());
+ }
- if (idx < parameters.length) {
- Object param = parameters[idx];
- if (parameters[idx] instanceof Integer) {
- if ((Integer)param < 0)
- throw newValidationError(n,
IgniteResource.INSTANCE.correctIntegerLimit(nodeName));
+ throw newValidationError(n, err);
}
+ else
+ checkLimitOffset((Number)param, n, nodeName);
}
}
}
+ /** */
+ private void checkLimitOffset(Number offsetFetchLimit, @Nullable SqlNode
n, String nodeName) {
+ try {
+ long res = IgniteMath.convertToLongExact(offsetFetchLimit);
+
+ if (res < 0)
+ throw newValidationError(n,
IgniteResource.INSTANCE.illegalFetchLimit(nodeName));
+ }
+ catch (ArithmeticException e) {
+ throw newValidationError(n,
IgniteResource.INSTANCE.illegalFetchLimit(nodeName));
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void validateNamespace(SqlValidatorNamespace
namespace, RelDataType targetRowType) {
Review Comment:
I don't know, try doing a rebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]