@Test public void testOrderUnionOrdinal() { if (!tester.getConformance().isSortByOrdinal()) { return; } check( "select empno, sal from emp " + "union all " + "select deptno, deptno from dept " + "order by 2", "${plan}"); }
@Test public void testOrderUnionOrdinal() { if (!tester.getConformance().isSortByOrdinal()) { return; } check( "select empno, sal from emp " + "union all " + "select deptno, deptno from dept " + "order by 2", "${plan}"); }
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 SortRel's are 0-based int ordinal = intValue - 1; return nthSelectItem(ordinal, literal.getParserPosition()); } break; } } return super.visit(literal); }
@Test public void testOrderByOrdinalDesc() { // FRG-98 if (!tester.getConformance().isSortByOrdinal()) { return; } check( "select empno + 1, deptno, empno from emp order by 2 desc", "${plan}"); // ordinals rounded down, so 2.5 should have same effect as 2, and // generate identical plan check( "select empno + 1, deptno, empno from emp order by 2.5 desc", "${plan}"); }
@Test public void testOrderByOrdinalDesc() { // FRG-98 if (!tester.getConformance().isSortByOrdinal()) { return; } check( "select empno + 1, deptno, empno from emp order by 2 desc", "${plan}"); // ordinals rounded down, so 2.5 should have same effect as 2, and // generate identical plan check( "select empno + 1, deptno, empno from emp order by 2.5 desc", "${plan}"); }
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()) { if ((literal.getTypeName() == SqlTypeName.DECIMAL) || (literal.getTypeName() == SqlTypeName.DOUBLE)) { final int intValue = literal.intValue(false); if (intValue >= 0) { if ((intValue < 1) || (intValue > aliasList.size())) { throw newValidationError( literal, EigenbaseResource.instance() .OrderByOrdinalOutOfRange.ex()); } // SQL ordinals are 1-based, but SortRel's are 0-based int ordinal = intValue - 1; return nthSelectItem( ordinal, literal.getParserPosition()); } } } return super.visit(literal); }
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");
if (tester.getConformance().isSortByOrdinal()) { check( "select distinct cast(empno as bigint) from emp order by 1");