-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add supports to Insert Into #9
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e96d7ff
Add supports to Insert Into
weiqingy 6597f6b
Add unit tests
weiqingy cef398f
reorder imports
weiqingy 413b40b
Fix failure
weiqingy 5ad4d07
Fix review comments
weiqingy b185234
Add unit tests for CreateViewHarvester
weiqingy e8a772b
Fix a small issue
weiqingy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
94 changes: 94 additions & 0 deletions
94
...s-connector/src/test/scala/com/hortonworks/spark/atlas/sql/CreateViewHarvesterSuite.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,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.hortonworks.spark.atlas.sql | ||
|
||
import java.io.File | ||
import java.util | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.util.Random | ||
|
||
import org.apache.atlas.AtlasClient | ||
import org.apache.atlas.model.instance.AtlasEntity | ||
import org.apache.commons.io.FileUtils | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.execution.command.{ExecutedCommandExec, CreateViewCommand} | ||
import org.scalatest.{BeforeAndAfterAll, Matchers, FunSuite} | ||
|
||
import com.hortonworks.spark.atlas.types.external | ||
|
||
class CreateViewHarvesterSuite extends FunSuite with Matchers with BeforeAndAfterAll { | ||
private var sparkSession: SparkSession = _ | ||
private val sourceTblName = "source_" + Random.nextInt(100000) | ||
private val destinationViewName = "destination_" + Random.nextInt(100000) | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
sparkSession = SparkSession.builder() | ||
.master("local") | ||
.config("spark.sql.catalogImplementation", "hive") | ||
.getOrCreate() | ||
|
||
sparkSession.sql(s"CREATE TABLE $sourceTblName (name string)") | ||
sparkSession.sql(s"INSERT INTO TABLE $sourceTblName VALUES ('lucy'), ('tom')") | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
sparkSession.stop() | ||
SparkSession.clearActiveSession() | ||
SparkSession.clearDefaultSession() | ||
sparkSession = null | ||
|
||
FileUtils.deleteDirectory(new File("metastore_db")) | ||
FileUtils.deleteDirectory(new File("spark-warehouse")) | ||
|
||
super.afterAll() | ||
} | ||
|
||
test("CREATE VIEW FROM TABLE") { | ||
val qe = sparkSession.sql(s"CREATE VIEW $destinationViewName " + | ||
s"AS SELECT * FROM $sourceTblName").queryExecution | ||
val qd = QueryDetail(qe, 0L, 0L) | ||
|
||
assert(qe.sparkPlan.isInstanceOf[ExecutedCommandExec]) | ||
val node = qe.sparkPlan.asInstanceOf[ExecutedCommandExec] | ||
assert(node.cmd.isInstanceOf[CreateViewCommand]) | ||
val cmd = node.cmd.asInstanceOf[CreateViewCommand] | ||
|
||
val entities = CommandsHarvester.CreateViewHarvester.harvest(cmd, qd) | ||
val pEntity = entities.head | ||
|
||
assert(pEntity.getAttribute("inputs").isInstanceOf[util.Collection[_]]) | ||
val inputs = pEntity.getAttribute("inputs").asInstanceOf[util.Collection[AtlasEntity]] | ||
inputs.size() should be (1) | ||
|
||
val inputTbl = inputs.asScala.head | ||
inputTbl.getTypeName should be (external.HIVE_TABLE_TYPE_STRING) | ||
inputTbl.getAttribute("name") should be (sourceTblName) | ||
inputTbl.getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME).toString should be ( | ||
s"default.$sourceTblName@primary") | ||
|
||
assert(pEntity.getAttribute("outputs").isInstanceOf[util.Collection[_]]) | ||
val outputs = pEntity.getAttribute("outputs").asInstanceOf[util.Collection[AtlasEntity]] | ||
outputs.size() should be (1) | ||
val outputView = outputs.asScala.head | ||
outputView.getAttribute("name") should be (destinationViewName) | ||
outputView.getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME).toString should endWith ( | ||
s"default.$destinationViewName") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test case for this? Otherwise, can we add this in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, not yet. I'll add unit tests for CreateViewCommand