Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ grammar SqlBase;
* When true, the behavior of keywords follows ANSI SQL standard.
*/
public boolean SQL_standard_keyword_behavior = false;

/**
* When true, an INTERVAL keyword can be optional for interval values in SQL statements.
*/
public boolean optional_interval = false;
}

singleStatement
Expand Down Expand Up @@ -788,7 +793,7 @@ booleanValue

interval
: INTERVAL (errorCapturingMultiUnitsInterval | errorCapturingUnitToUnitInterval)?
| {SQL_standard_keyword_behavior}? (errorCapturingMultiUnitsInterval | errorCapturingUnitToUnitInterval)
| {optional_interval}? (errorCapturingMultiUnitsInterval | errorCapturingUnitToUnitInterval)
;

errorCapturingMultiUnitsInterval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ abstract class AbstractSqlParser(conf: SQLConf) extends ParserInterface with Log
lexer.addErrorListener(ParseErrorListener)
lexer.legacy_setops_precedence_enbled = conf.setOpsPrecedenceEnforced
lexer.SQL_standard_keyword_behavior = SQLStandardKeywordBehavior
lexer.optional_interval = conf.optionalInterval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be dialect == Spark && ansi == true && optionalInterval

For pgsql diaelct, INTERVAL can't be optional. for non-ansi mode, year/month/day... are not reserved keywords and we can't ommit INTERVAL prefix anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


val tokenStream = new CommonTokenStream(lexer)
val parser = new SqlBaseParser(tokenStream)
Expand All @@ -109,6 +110,7 @@ abstract class AbstractSqlParser(conf: SQLConf) extends ParserInterface with Log
parser.addErrorListener(ParseErrorListener)
parser.legacy_setops_precedence_enbled = conf.setOpsPrecedenceEnforced
parser.SQL_standard_keyword_behavior = SQLStandardKeywordBehavior
parser.optional_interval = conf.optionalInterval

try {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,13 @@ object SQLConf {
val SQL_STANDARD, ISO_8601, MULTI_UNITS = Value
}

val OPTIONAL_INTERVAL =
buildConf("spark.sql.optionalInterval")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put it under the spark.sql.parser namespace

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

.doc("When true, an INTERVAL keyword can be optional for interval values in SQL statements," +
" e.g., 'SELECT 1 day'.")
.booleanConf
.createWithDefault(false)

val INTERVAL_STYLE = buildConf("spark.sql.intervalOutputStyle")
.doc("When converting interval values to strings (i.e. for display), this config decides the" +
" interval string format. The value SQL_STANDARD will produce output matching SQL standard" +
Expand Down Expand Up @@ -2513,6 +2520,8 @@ class SQLConf extends Serializable with Logging {
def storeAssignmentPolicy: StoreAssignmentPolicy.Value =
StoreAssignmentPolicy.withName(getConf(STORE_ASSIGNMENT_POLICY))

def optionalInterval: Boolean = getConf(OPTIONAL_INTERVAL)

def intervalOutputStyle: IntervalStyle.Value = IntervalStyle.withName(getConf(INTERVAL_STYLE))

def dialect: Dialect.Value = Dialect.withName(getConf(DIALECT))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--SET spark.sql.optionalInterval=true
--IMPORT interval.sql

-- the `interval` keyword can be omitted with ansi mode
Expand Down