Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11148#discussion_r52825188
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -80,6 +81,26 @@ class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: 
SQLContext) extends Loggi
         case p: Limit =>
           s"${toSQL(p.child)} LIMIT ${p.limitExpr.sql}"
     
    +    // TABLESAMPLE is part of tableSource clause in the parser,
    +    // and thus we must handle it with subquery.
    +    case p @ Sample(lb, ub, withReplacement, _, _)
    +        if !withReplacement && lb <= (ub + RandomSampler.roundingEpsilon) 
=>
    +      val fraction = math.min(100, math.max(0, (ub - lb) * 100))
    +      p.child match {
    +        case m: MetastoreRelation =>
    +          val aliasName = m.alias.getOrElse("")
    +          build(
    +            s"`${m.databaseName}`.`${m.tableName}`",
    +            "TABLESAMPLE(" + fraction + " PERCENT)",
    +            aliasName)
    +        case s: Subquery =>
    +          val aliasName = if (s.child.isInstanceOf[Subquery]) s.alias else 
""
    +          val plan = if (s.child.isInstanceOf[Subquery]) s.child else s
    +          build(toSQL(plan), "TABLESAMPLE(" + fraction + " PERCENT)", 
aliasName)
    +        case _ =>
    --- End diff --
    
    Unable to create a test case for this branch. I do not know if we should 
throw an exception here or building a SQL.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to