public SqlNode visit(SqlLiteral literal) { // Ordinal markers, e.g. 'select a, b from t order by 2'. // Only recognize them if they are the whole expression, // and if the dialect permits. if (literal == root && getConformance().isSortByOrdinal()) { switch (literal.getTypeName()) { case DECIMAL: case DOUBLE: final int intValue = literal.intValue(false); if (intValue >= 0) { if (intValue < 1 || intValue > aliasList.size()) { throw newValidationError( literal, RESOURCE.orderByOrdinalOutOfRange()); } // SQL ordinals are 1-based, but Sort's are 0-based int ordinal = intValue - 1; return nthSelectItem(ordinal, literal.getParserPosition()); } break; } } return super.visit(literal); }
@Override public boolean isSortByOrdinal() { return delegate.isSortByOrdinal(); }
@Override public boolean isSortByOrdinal() { return delegate.isSortByOrdinal(); }
public SqlNode visit(SqlLiteral literal) { // Ordinal markers, e.g. 'select a, b from t order by 2'. // Only recognize them if they are the whole expression, // and if the dialect permits. if (literal == root && getConformance().isSortByOrdinal()) { switch (literal.getTypeName()) { case DECIMAL: case DOUBLE: final int intValue = literal.intValue(false); if (intValue >= 0) { if (intValue < 1 || intValue > aliasList.size()) { throw newValidationError( literal, RESOURCE.orderByOrdinalOutOfRange()); } // SQL ordinals are 1-based, but Sort's are 0-based int ordinal = intValue - 1; return nthSelectItem(ordinal, literal.getParserPosition()); } break; } } return super.visit(literal); }
public SqlNode visit(SqlLiteral literal) { // Ordinal markers, e.g. 'select a, b from t order by 2'. // Only recognize them if they are the whole expression, // and if the dialect permits. if (literal == root && getConformance().isSortByOrdinal()) { switch (literal.getTypeName()) { case DECIMAL: case DOUBLE: final int intValue = literal.intValue(false); if (intValue >= 0) { if (intValue < 1 || intValue > aliasList.size()) { throw newValidationError( literal, RESOURCE.orderByOrdinalOutOfRange()); } // SQL ordinals are 1-based, but Sort's are 0-based int ordinal = intValue - 1; return nthSelectItem(ordinal, literal.getParserPosition()); } break; } } return super.visit(literal); }
@Test public void testOrderUnionOrdinal() { if (!tester.getConformance().isSortByOrdinal()) { return; } final String sql = "select empno, sal from emp\n" + "union all\n" + "select deptno, deptno from dept\n" + "order by 2"; sql(sql).ok(); }
@Test public void testOrderUnionOrdinal() { if (!tester.getConformance().isSortByOrdinal()) { return; } final String sql = "select empno, sal from emp\n" + "union all\n" + "select deptno, deptno from dept\n" + "order by 2"; sql(sql).ok(); }
@Test public void testOrderByOrdinalDesc() { // FRG-98 if (!tester.getConformance().isSortByOrdinal()) { return; } final String sql = "select empno + 1, deptno, empno from emp order by 2 desc"; sql(sql).ok(); // ordinals rounded down, so 2.5 should have same effect as 2, and // generate identical plan final String sql2 = "select empno + 1, deptno, empno from emp order by 2.5 desc"; sql(sql2).ok(); }
@Test public void testOrderByOrdinalDesc() { // FRG-98 if (!tester.getConformance().isSortByOrdinal()) { return; } final String sql = "select empno + 1, deptno, empno from emp order by 2 desc"; sql(sql).ok(); // ordinals rounded down, so 2.5 should have same effect as 2, and // generate identical plan final String sql2 = "select empno + 1, deptno, empno from emp order by 2.5 desc"; sql(sql2).ok(); }
if (tester.getConformance().isSortByOrdinal()) { checkFails( "select empno, sal from emp "
if (tester.getConformance().isSortByOrdinal()) { checkFails( "select empno, sal from emp "
conformance.isSortByOrdinal() ? "Ordinal out of range" conformance.isSortByOrdinal() ? "Ordinal out of range" : null);
conformance.isSortByOrdinal() ? "Ordinal out of range" conformance.isSortByOrdinal() ? "Ordinal out of range" : null);
if (tester.getConformance().isSortByOrdinal()) { check("select distinct cast(empno as bigint) from emp order by 1"); check("select distinct cast(empno as bigint) as empno "
if (tester.getConformance().isSortByOrdinal()) { check("select distinct cast(empno as bigint) from emp order by 1"); check("select distinct cast(empno as bigint) as empno "