Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29.4k
[SPARK-20254][SQL] Remove unnecessary data conversion for Dataset with primitive array#17568
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1ece803c042ff2264a18b82a1f2bcc3c7bd7d43d273bcee3f1b24be05174b5ee608c452ee40301d6ab360fd8c25791aad9f695e50ce6927da6bedeec0dca2b8de6915File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,6 +23,7 @@ import org.apache.spark.sql.catalyst.analysis._ | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate._ | ||
| import org.apache.spark.sql.catalyst.expressions.Literal.{FalseLiteral, TrueLiteral} | ||
| import org.apache.spark.sql.catalyst.expressions.objects.AssertNotNull | ||
| import org.apache.spark.sql.catalyst.plans._ | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.rules._ | ||
| @@ -368,6 +369,8 @@ case class NullPropagation(conf: SQLConf) extends Rule[LogicalPlan] { | ||
| case EqualNullSafe(Literal(null, _), r) => IsNull(r) | ||
| case EqualNullSafe(l, Literal(null, _)) => IsNull(l) | ||
| case AssertNotNull(c, _) if !c.nullable => c | ||
Member 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. Is this safe to do? According to the description of MemberAuthor 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 think that this is what @cloud-fan suggested in his comment. Member 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 am not sure if @cloud-fan's no-op 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. ah good catch! sorry it was my mistake, but then seems we can not remove 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, I checked all the usage of MemberAuthor 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 agree with @cloud-fan. I have also checked the usages of Member 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 think the purpose of Maybe for 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. as long as we trust the Member 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. OK. Sounds reasonable to me. | ||
| // For Coalesce, remove null literals. | ||
| case e @ Coalesce(children) => | ||
| val newChildren = children.filterNot(isNullLiteral) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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.catalyst.optimizer | ||
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
| import org.apache.spark.sql.catalyst.dsl.plans._ | ||
| import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder | ||
| import org.apache.spark.sql.catalyst.expressions.AttributeReference | ||
| import org.apache.spark.sql.catalyst.expressions.objects.Invoke | ||
| import org.apache.spark.sql.catalyst.plans.PlanTest | ||
| import org.apache.spark.sql.catalyst.plans.logical.{DeserializeToObject, LocalRelation, LogicalPlan} | ||
| import org.apache.spark.sql.catalyst.rules.RuleExecutor | ||
| import org.apache.spark.sql.types._ | ||
| class EliminateMapObjectsSuite extends PlanTest { | ||
| object Optimize extends RuleExecutor[LogicalPlan] { | ||
| val batches = { | ||
| Batch("EliminateMapObjects", FixedPoint(50), | ||
| NullPropagation(conf), | ||
| SimplifyCasts, | ||
| EliminateMapObjects) :: Nil | ||
| } | ||
| } | ||
| implicit private def intArrayEncoder = ExpressionEncoder[Array[Int]]() | ||
| implicit private def doubleArrayEncoder = ExpressionEncoder[Array[Double]]() | ||
| test("SPARK-20254: Remove unnecessary data conversion for primitive array") { | ||
| val intObjType = ObjectType(classOf[Array[Int]]) | ||
| val intInput = LocalRelation('a.array(ArrayType(IntegerType, false))) | ||
| val intQuery = intInput.deserialize[Array[Int]].analyze | ||
| val intOptimized = Optimize.execute(intQuery) | ||
| val intExpected = DeserializeToObject( | ||
| Invoke(intInput.output(0), "toIntArray", intObjType, Nil, true, false), | ||
| AttributeReference("obj", intObjType, true)(), intInput) | ||
| comparePlans(intOptimized, intExpected) | ||
| val doubleObjType = ObjectType(classOf[Array[Double]]) | ||
| val doubleInput = LocalRelation('a.array(ArrayType(DoubleType, false))) | ||
| val doubleQuery = doubleInput.deserialize[Array[Double]].analyze | ||
| val doubleOptimized = Optimize.execute(doubleQuery) | ||
| val doubleExpected = DeserializeToObject( | ||
| Invoke(doubleInput.output(0), "toDoubleArray", doubleObjType, Nil, true, false), | ||
| AttributeReference("obj", doubleObjType, true)(), doubleInput) | ||
| comparePlans(doubleOptimized, doubleExpected) | ||
| } | ||
| } |
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.
Add
@param?