-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-9986][SPARK-9991][SPARK-9993][SQL]Create a simple test framework for local operators #8464
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
Changes from all commits
4dc2583
99433c1
4e101ee
76bae2e
62b8d24
22e7bc0
094d361
ea263f5
7dcd502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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 org.apache.spark.sql.execution.local | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
|
|
||
|
|
||
| case class LimitNode(limit: Int, child: LocalNode) extends UnaryLocalNode { | ||
|
|
||
| private[this] var count = 0 | ||
|
|
||
| override def output: Seq[Attribute] = child.output | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do iterators need to know their
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I guess this is useful for |
||
|
|
||
| override def open(): Unit = child.open() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also reset the count?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LocalNode cannot be reused, just like Iterator. So it's not necessary to reset it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it'd be great to have a reset method in addition to open so we can revisit result of the iterator. We can do that later. |
||
|
|
||
| override def close(): Unit = child.close() | ||
|
|
||
| override def fetch(): InternalRow = child.fetch() | ||
|
|
||
| override def next(): Boolean = { | ||
| if (count < limit) { | ||
| count += 1 | ||
| child.next() | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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 org.apache.spark.sql.execution.local | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
|
|
||
| case class UnionNode(children: Seq[LocalNode]) extends LocalNode { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we add an assert to make sure all children have same output?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different children may have different
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider making this an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on making this Array
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It overrides |
||
|
|
||
| override def output: Seq[Attribute] = children.head.output | ||
|
|
||
| private[this] var currentChild: LocalNode = _ | ||
|
|
||
| private[this] var nextChildIndex: Int = _ | ||
|
|
||
| override def open(): Unit = { | ||
| currentChild = children.head | ||
| currentChild.open() | ||
| nextChildIndex = 1 | ||
| } | ||
|
|
||
| private def advanceToNextChild(): Boolean = { | ||
| var found = false | ||
| var exit = false | ||
| while (!exit && !found) { | ||
| if (currentChild != null) { | ||
| currentChild.close() | ||
| } | ||
| if (nextChildIndex >= children.size) { | ||
| found = false | ||
| exit = true | ||
| } else { | ||
| currentChild = children(nextChildIndex) | ||
| nextChildIndex += 1 | ||
| currentChild.open() | ||
| found = currentChild.next() | ||
| } | ||
| } | ||
| found | ||
| } | ||
|
|
||
| override def close(): Unit = { | ||
| if (currentChild != null) { | ||
| currentChild.close() | ||
| } | ||
| } | ||
|
|
||
| override def fetch(): InternalRow = currentChild.fetch() | ||
|
|
||
| override def next(): Boolean = { | ||
| if (currentChild.next()) { | ||
| true | ||
| } else { | ||
| advanceToNextChild() | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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 org.apache.spark.sql.execution.local | ||
|
|
||
| import org.apache.spark.sql.test.SharedSQLContext | ||
|
|
||
| class FilterNodeSuite extends LocalNodeTest with SharedSQLContext { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so I was thinking it would be great if we can get rid of the SQLContext in the test cases for these local stuff.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just want to reuse
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that SQLTestData is going away though.... #7406
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Didn't notice that. I will add test data for each test case manually.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realized we need to call |
||
|
|
||
| test("basic") { | ||
| val condition = (testData.col("key") % 2) === 0 | ||
| checkAnswer( | ||
| testData, | ||
| node => FilterNode(condition.expr, node), | ||
| testData.filter(condition).collect() | ||
| ) | ||
| } | ||
|
|
||
| test("empty") { | ||
| val condition = (emptyTestData.col("key") % 2) === 0 | ||
| checkAnswer( | ||
| emptyTestData, | ||
| node => FilterNode(condition.expr, node), | ||
| emptyTestData.filter(condition).collect() | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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 org.apache.spark.sql.execution.local | ||
|
|
||
| import org.apache.spark.sql.test.SharedSQLContext | ||
|
|
||
| class LimitNodeSuite extends LocalNodeTest with SharedSQLContext { | ||
|
|
||
| test("basic") { | ||
| checkAnswer( | ||
| testData, | ||
| node => LimitNode(10, node), | ||
| testData.limit(10).collect() | ||
| ) | ||
| } | ||
|
|
||
| test("empty") { | ||
| checkAnswer( | ||
| emptyTestData, | ||
| node => LimitNode(10, node), | ||
| emptyTestData.limit(10).collect() | ||
| ) | ||
| } | ||
| } |
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.
Is there a need to distinguish
Unaryoperators from others?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.
Maybe more generally, if we are never going to do transformations of these iterator trees, do they need to inherit from
TreeNode?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.
I think we still need
filter, ormapfor these iterator trees. @rxin is there anything I misunderstand for theLocalNodedesign?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.
It may or may not. We can remove them later though.