Skip to content

Lack of support for the ANSI SQL syntax FETCH FIRST N ROWS WITH TIES #23223

Open
@linghengqian

Description

@linghengqian

Expected Behavior or Use Case

  • Add support for ANSI SQL syntax FETCH FIRST N ROWS WITH TIES. The actual SQL might look like the following.
CREATE TABLE memory.default.table_with_array AS SELECT 1 id, ARRAY[1, 42, 2, 42, 4, 42] my_array

SELECT nationkey, element 
FROM tpch.tiny.nation 
JOIN memory.default.table_with_array twa ON nationkey = twa.id 
CROSS JOIN UNNEST(my_array) a(element) 
ORDER BY element OFFSET 1 FETCH FIRST 3 ROWS WITH TIES
line 1:196: mismatched input 'WITH'. Expecting: 'ONLY'
com.facebook.presto.sql.parser.ParsingException: line 1:196: mismatched input 'WITH'. Expecting: 'ONLY'
	at com.facebook.presto.sql.parser.ErrorHandler.syntaxError(ErrorHandler.java:109)
	at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
	at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544)
	at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327)
	at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139)
	at com.facebook.presto.sql.parser.SqlBaseParser.queryNoWith(SqlBaseParser.java:5965)
	at com.facebook.presto.sql.parser.SqlBaseParser.query(SqlBaseParser.java:4643)
	at com.facebook.presto.sql.parser.SqlBaseParser.statement(SqlBaseParser.java:2189)
	at com.facebook.presto.sql.parser.SqlBaseParser.singleStatement(SqlBaseParser.java:271)
	at com.facebook.presto.sql.parser.SqlParser.invokeParser(SqlParser.java:173)
	at com.facebook.presto.sql.parser.SqlParser.createStatement(SqlParser.java:108)
	at com.facebook.presto.sql.analyzer.BuiltInQueryPreparer.prepareQuery(BuiltInQueryPreparer.java:70)
	at com.facebook.presto.sql.analyzer.BuiltInQueryPreparer.prepareQuery(BuiltInQueryPreparer.java:56)
	at com.facebook.presto.dispatcher.DispatchManager.createQueryInternal(DispatchManager.java:290)
	at com.facebook.presto.dispatcher.DispatchManager.lambda$createQuery$0(DispatchManager.java:254)
	at com.facebook.airlift.concurrent.BoundedExecutor.drainQueue(BoundedExecutor.java:78)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.antlr.v4.runtime.InputMismatchException
	at com.facebook.presto.sql.parser.SqlParser$2.recoverInline(SqlParser.java:147)
	at org.antlr.v4.runtime.Parser.match(Parser.java:206)
	at com.facebook.presto.sql.parser.SqlBaseParser.queryNoWith(SqlBaseParser.java:5947)
	... 13 more

Presto Component, Service, or Connector

  • Presto Service.

Possible Implementation

  • I lack the expertise in this area, so I'm afraid there's nothing I can do.

Example Screenshots (if appropriate):

  • I don't think a screenshot is necessary.

Context

SELECT nationkey, element 
FROM tpch.tiny.nation 
JOIN memory.default.table_with_array twa ON nationkey = twa.id 
CROSS JOIN UNNEST(my_array) a(element) 
ORDER BY element OFFSET 1 FETCH FIRST 3 ROWS ONLY 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions