carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipesala <...@git.apache.org>
Subject [GitHub] carbondata pull request #954: [WIP] IUD support in 2.1
Date Mon, 29 May 2017 06:09:22 GMT
Github user ravipesala commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/954#discussion_r118870746
  
    --- Diff: integration/spark2/src/main/scala/org/apache/spark/sql/parser/CarbonSpark2SqlParser.scala
---
    @@ -78,6 +80,128 @@ class CarbonSpark2SqlParser extends CarbonDDLSqlParser {
             AlterTableCompaction(altertablemodel)
         }
     
    +  protected lazy val deleteRecords: Parser[LogicalPlan] =
    +    (DELETE ~> FROM ~> table) ~ restInput.? <~ opt(";") ^^ {
    +      case table ~ rest =>
    +        val tableName = getTableName(table.tableIdentifier)
    +        val alias = table.alias.getOrElse("")
    +        DeleteRecords("select tupleId from " + tableName + " " + alias + rest.getOrElse(""),
table)
    +    }
    +
    +  protected lazy val updateTable: Parser[LogicalPlan] =
    +    UPDATE ~> table ~
    +    (SET ~> "(" ~> repsep(element, ",") <~ ")") ~
    +    ("=" ~> restInput) <~ opt(";") ^^ {
    +      case tab ~ columns ~ rest =>
    +        val (sel, where) = splitQuery(rest)
    +        val (selectStmt, relation) =
    +          if (!sel.toLowerCase.startsWith("select ")) {
    +            if (sel.trim.isEmpty) {
    +              sys.error("At least one source column has to be specified ")
    +            }
    +            // only list of expression are given, need to convert that list of expressions
into
    +            // select statement on destination table
    +            val relation = tab match {
    +              case r@UnresolvedRelation(tableIdentifier, alias) =>
    +                updateRelation(r, tableIdentifier, alias)
    +              case _ => tab
    +            }
    +            ("select " + sel + " from " + getTableName(relation.tableIdentifier) + "
" +
    +             relation.alias.get, relation)
    +          } else {
    +            (sel, updateRelation(tab, tab.tableIdentifier, tab.alias))
    +          }
    +        UpdateTable(relation, columns, selectStmt, where)
    +    }
    +
    +  private def updateRelation(
    +      r: UnresolvedRelation,
    +      tableIdentifier: Seq[String],
    +      alias: Option[String]): UnresolvedRelation = {
    +    alias match {
    +      case Some(_) => r
    +      case _ =>
    +        val tableAlias = tableIdentifier match {
    +          case Seq(dbName, tableName) => Some(tableName)
    +          case Seq(tableName) => Some(tableName)
    +        }
    +        UnresolvedRelation(tableIdentifier, Option(tableAlias.toString))
    --- End diff --
    
    Just pass as tableAlias, it already an option


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message