aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst
diff options
context:
space:
mode:
Diffstat (limited to 'sql/catalyst')
-rw-r--r--sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g47
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala12
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala6
3 files changed, 22 insertions, 3 deletions
diff --git a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
index cc4e5c853e..3ab448dd9e 100644
--- a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
+++ b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
@@ -389,7 +389,8 @@ sample
: TABLESAMPLE '('
( (percentage=(INTEGER_VALUE | DECIMAL_VALUE) sampleType=PERCENTLIT)
| (expression sampleType=ROWS)
- | (sampleType=BUCKET numerator=INTEGER_VALUE OUT OF denominator=INTEGER_VALUE (ON identifier)?))
+ | sampleType=BYTELENGTH_LITERAL
+ | (sampleType=BUCKET numerator=INTEGER_VALUE OUT OF denominator=INTEGER_VALUE (ON (identifier | qualifiedName '(' ')'))?))
')'
;
@@ -895,6 +896,10 @@ TINYINT_LITERAL
: DIGIT+ 'Y'
;
+BYTELENGTH_LITERAL
+ : DIGIT+ ('B' | 'K' | 'M' | 'G')
+ ;
+
INTEGER_VALUE
: DIGIT+
;
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
index c3974625aa..1d4e1ec3b8 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@@ -632,8 +632,18 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with Logging {
val fraction = ctx.percentage.getText.toDouble
sample(fraction / 100.0d)
+ case SqlBaseParser.BYTELENGTH_LITERAL =>
+ throw new ParseException(
+ "TABLESAMPLE(byteLengthLiteral) is not supported", ctx)
+
case SqlBaseParser.BUCKET if ctx.ON != null =>
- throw new ParseException("TABLESAMPLE(BUCKET x OUT OF y ON id) is not supported", ctx)
+ if (ctx.identifier != null) {
+ throw new ParseException(
+ "TABLESAMPLE(BUCKET x OUT OF y ON colname) is not supported", ctx)
+ } else {
+ throw new ParseException(
+ "TABLESAMPLE(BUCKET x OUT OF y ON function) is not supported", ctx)
+ }
case SqlBaseParser.BUCKET =>
sample(ctx.numerator.getText.toDouble / ctx.denominator.getText.toDouble)
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala
index b7af2ceda6..aaf84268af 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala
@@ -372,9 +372,13 @@ class PlanParserSuite extends PlanTest {
assertEqual(s"$sql tablesample(bucket 4 out of 10) as x",
Sample(0, .4d, withReplacement = false, 10L, table("t").as("x"))(true).select(star()))
intercept(s"$sql tablesample(bucket 4 out of 10 on x) as x",
- "TABLESAMPLE(BUCKET x OUT OF y ON id) is not supported")
+ "TABLESAMPLE(BUCKET x OUT OF y ON colname) is not supported")
intercept(s"$sql tablesample(bucket 11 out of 10) as x",
s"Sampling fraction (${11.0/10.0}) must be on interval [0, 1]")
+ intercept("SELECT * FROM parquet_t0 TABLESAMPLE(300M) s",
+ "TABLESAMPLE(byteLengthLiteral) is not supported")
+ intercept("SELECT * FROM parquet_t0 TABLESAMPLE(BUCKET 3 OUT OF 32 ON rand()) s",
+ "TABLESAMPLE(BUCKET x OUT OF y ON function) is not supported")
}
test("sub-query") {