forked from delta-io/delta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CARMEL-1440] Enable Delta Lake SQL on Carmel Spark-2.3
- Loading branch information
Showing
7 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/scala/io/delta/sql/analysis/DeltaSqlResolution.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2019 Databricks, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.sql.analysis | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedRelation} | ||
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, UpdateTable} | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.execution.datasources.UpdateTableIdentifier | ||
|
||
class DeltaSqlResolution(spark: SparkSession) extends Rule[LogicalPlan] { | ||
|
||
override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { | ||
case UpdateTableIdentifier(tableIdentifier, c, values, condition) => | ||
val table = UnresolvedRelation(tableIdentifier) | ||
val columns = c.map(UnresolvedAttribute(_)) | ||
UpdateTable(table, columns, values, condition) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/scala/io/delta/sql/analysis/PreprocessTableUpdate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2019 Databricks, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.sql.analysis | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, UnresolvedAttribute} | ||
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, UpdateTable} | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.delta.commands.UpdateCommand | ||
import org.apache.spark.sql.delta.{DeltaErrors, DeltaFullTable, UpdateExpressionsSupport} | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
||
class PreprocessTableUpdate( | ||
spark: SparkSession) extends Rule[LogicalPlan] with UpdateExpressionsSupport { | ||
|
||
def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperatorsDown { | ||
case update: UpdateTable => | ||
val index = EliminateSubqueryAliases(update.child) match { | ||
case DeltaFullTable(tahoeFileIndex) => | ||
tahoeFileIndex | ||
case o => | ||
throw DeltaErrors.notADeltaSourceException("UPDATE", Some(o)) | ||
} | ||
|
||
val targetColNameParts = | ||
update.updateColumns.map{col => new UnresolvedAttribute(col.name.split("\\.")).nameParts} | ||
|
||
val alignedUpdateExprs = generateUpdateExpressions( | ||
update.child.output, targetColNameParts, update.updateExpressions, conf.resolver) | ||
UpdateCommand(index, update.child, alignedUpdateExprs, update.condition) | ||
} | ||
|
||
override def conf: SQLConf = spark.sessionState.conf | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/scala/io/delta/sql/execution/DeltaSqlStrategy.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2019 Databricks, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.delta.sql.execution | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
import org.apache.spark.sql.delta.commands.UpdateCommand | ||
import org.apache.spark.sql.execution.{SparkPlan, SparkStrategy} | ||
|
||
case class DeltaSqlStrategy(spark: SparkSession) extends SparkStrategy { | ||
def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match { | ||
case u @ UpdateCommand(_, _, _, _) => | ||
u.run(spark) | ||
Nil | ||
case _ => Nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version in ThisBuild := "0.4.1-SNAPSHOT" | ||
version in ThisBuild := "0.4.0.carmel0.1-SNAPSHOT" |