Skip to content

Commit 5b39c02

Browse files
committed
Merge remote-tracking branch 'upstream/master' into expr_binary_log
Conflicts: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala
2 parents 23c54a3 + 767cc94 commit 5b39c02

File tree

66 files changed

+861
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+861
-540
lines changed

core/src/test/scala/org/apache/spark/ui/UISeleniumSuite.scala

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
2323
import scala.collection.JavaConversions._
2424
import scala.xml.Node
2525

26+
import com.gargoylesoftware.htmlunit.DefaultCssErrorHandler
2627
import org.json4s._
2728
import org.json4s.jackson.JsonMethods
2829
import org.openqa.selenium.htmlunit.HtmlUnitDriver
@@ -31,6 +32,7 @@ import org.scalatest._
3132
import org.scalatest.concurrent.Eventually._
3233
import org.scalatest.selenium.WebBrowser
3334
import org.scalatest.time.SpanSugar._
35+
import org.w3c.css.sac.CSSParseException
3436

3537
import org.apache.spark.LocalSparkContext._
3638
import org.apache.spark._
@@ -39,6 +41,31 @@ import org.apache.spark.deploy.history.HistoryServerSuite
3941
import org.apache.spark.shuffle.FetchFailedException
4042
import org.apache.spark.status.api.v1.{JacksonMessageWriter, StageStatus}
4143

44+
private[spark] class SparkUICssErrorHandler extends DefaultCssErrorHandler {
45+
46+
private val cssWhiteList = List("bootstrap.min.css", "vis.min.css")
47+
48+
private def isInWhileList(uri: String): Boolean = cssWhiteList.exists(uri.endsWith)
49+
50+
override def warning(e: CSSParseException): Unit = {
51+
if (!isInWhileList(e.getURI)) {
52+
super.warning(e)
53+
}
54+
}
55+
56+
override def fatalError(e: CSSParseException): Unit = {
57+
if (!isInWhileList(e.getURI)) {
58+
super.fatalError(e)
59+
}
60+
}
61+
62+
override def error(e: CSSParseException): Unit = {
63+
if (!isInWhileList(e.getURI)) {
64+
super.error(e)
65+
}
66+
}
67+
}
68+
4269
/**
4370
* Selenium tests for the Spark Web UI.
4471
*/
@@ -49,7 +76,9 @@ class UISeleniumSuite extends SparkFunSuite with WebBrowser with Matchers with B
4976

5077

5178
override def beforeAll(): Unit = {
52-
webDriver = new HtmlUnitDriver
79+
webDriver = new HtmlUnitDriver {
80+
getWebClient.setCssErrorHandler(new SparkUICssErrorHandler)
81+
}
5382
}
5483

5584
override def afterAll(): Unit = {

docs/hadoop-provided.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export SPARK_DIST_CLASSPATH=$(hadoop classpath)
2121
export SPARK_DIST_CLASSPATH=$(/path/to/hadoop/bin/hadoop classpath)
2222

2323
# Passing a Hadoop configuration directory
24-
export SPARK_DIST_CLASSPATH=$(hadoop classpath --config /path/to/configs)
24+
export SPARK_DIST_CLASSPATH=$(hadoop --config /path/to/configs classpath)
2525

2626
{% endhighlight %}

ec2/spark_ec2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
raw_input = input
5252
xrange = range
5353

54-
SPARK_EC2_VERSION = "1.3.1"
54+
SPARK_EC2_VERSION = "1.4.0"
5555
SPARK_EC2_DIR = os.path.dirname(os.path.realpath(__file__))
5656

5757
VALID_SPARK_VERSIONS = set([
@@ -89,7 +89,7 @@
8989

9090
# Default location to get the spark-ec2 scripts (and ami-list) from
9191
DEFAULT_SPARK_EC2_GITHUB_REPO = "https://github.com/mesos/spark-ec2"
92-
DEFAULT_SPARK_EC2_BRANCH = "branch-1.3"
92+
DEFAULT_SPARK_EC2_BRANCH = "branch-1.4"
9393

9494

9595
def setup_external_libs(libs):

project/SparkBuild.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ object SparkBuild extends PomBuild {
149149
javacOptions in (Compile, doc) ++= {
150150
val Array(major, minor, _) = System.getProperty("java.version").split("\\.", 3)
151151
if (major.toInt >= 1 && minor.toInt >= 8) Seq("-Xdoclint:all", "-Xdoclint:-missing") else Seq.empty
152-
}
152+
},
153+
154+
javacOptions in Compile ++= Seq("-encoding", "UTF-8")
153155
)
154156

155157
def enable(settings: Seq[Setting[_]])(projectRef: ProjectRef) = {

sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.apache.spark.sql.BaseMutableRow;
3131
import org.apache.spark.sql.types.DataType;
3232
import org.apache.spark.sql.types.StructType;
33-
import org.apache.spark.sql.types.UTF8String;
33+
import org.apache.spark.unsafe.types.UTF8String;
3434
import org.apache.spark.unsafe.PlatformDependent;
3535
import org.apache.spark.unsafe.bitset.BitSetMethods;
3636

sql/catalyst/src/main/scala/org/apache/spark/sql/BaseRow.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,27 @@ public int fieldIndex(String name) {
154154
throw new UnsupportedOperationException();
155155
}
156156

157+
/**
158+
* A generic version of Row.equals(Row), which is used for tests.
159+
*/
160+
@Override
161+
public boolean equals(Object other) {
162+
if (other instanceof Row) {
163+
Row row = (Row) other;
164+
int n = size();
165+
if (n != row.size()) {
166+
return false;
167+
}
168+
for (int i = 0; i < n; i ++) {
169+
if (isNullAt(i) != row.isNullAt(i) || (!isNullAt(i) && !get(i).equals(row.get(i)))) {
170+
return false;
171+
}
172+
}
173+
return true;
174+
}
175+
return false;
176+
}
177+
157178
@Override
158179
public Row copy() {
159180
final int n = size();

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/CatalystTypeConverters.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import scala.collection.mutable.HashMap
2828
import org.apache.spark.sql.catalyst.expressions._
2929
import org.apache.spark.sql.catalyst.util.DateUtils
3030
import org.apache.spark.sql.types._
31+
import org.apache.spark.unsafe.types.UTF8String
3132

3233
/**
3334
* Functions to convert Scala types to Catalyst types and vice versa.
@@ -257,7 +258,7 @@ object CatalystTypeConverters {
257258

258259
private object StringConverter extends CatalystTypeConverter[Any, String, Any] {
259260
override def toCatalystImpl(scalaValue: Any): UTF8String = scalaValue match {
260-
case str: String => UTF8String(str)
261+
case str: String => UTF8String.fromString(str)
261262
case utf8: UTF8String => utf8
262263
}
263264
override def toScala(catalystValue: Any): String = catalystValue match {

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.spark.sql.catalyst
1919

20+
import org.apache.spark.unsafe.types.UTF8String
2021
import org.apache.spark.util.Utils
2122
import org.apache.spark.sql.catalyst.expressions._
2223
import org.apache.spark.sql.catalyst.plans.logical.LocalRelation

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,43 +84,52 @@ object FunctionRegistry {
8484
type FunctionBuilder = Seq[Expression] => Expression
8585

8686
val expressions: Map[String, FunctionBuilder] = Map(
87-
// Non aggregate functions
87+
// misc non-aggregate functions
8888
expression[Abs]("abs"),
8989
expression[CreateArray]("array"),
9090
expression[Coalesce]("coalesce"),
9191
expression[Explode]("explode"),
92+
expression[If]("if"),
93+
expression[IsNull]("isnull"),
94+
expression[IsNotNull]("isnotnull"),
95+
expression[Coalesce]("nvl"),
9296
expression[Rand]("rand"),
9397
expression[Randn]("randn"),
9498
expression[CreateStruct]("struct"),
9599
expression[Sqrt]("sqrt"),
96100

97-
// Math functions
101+
// math functions
98102
expression[Acos]("acos"),
99103
expression[Asin]("asin"),
100104
expression[Atan]("atan"),
101105
expression[Atan2]("atan2"),
102106
expression[Cbrt]("cbrt"),
103107
expression[Ceil]("ceil"),
108+
expression[Ceil]("ceiling"),
104109
expression[Cos]("cos"),
105110
expression[EulerNumber]("e"),
106111
expression[Exp]("exp"),
107112
expression[Expm1]("expm1"),
108113
expression[Floor]("floor"),
109114
expression[Hypot]("hypot"),
110115
expression[Logarithm]("log"),
116+
expression[Log]("ln"),
111117
expression[Log10]("log10"),
112118
expression[Log1p]("log1p"),
119+
expression[UnaryMinus]("negative"),
113120
expression[Pi]("pi"),
114121
expression[Log2]("log2"),
115122
expression[Pow]("pow"),
123+
expression[Pow]("power"),
116124
expression[Rint]("rint"),
125+
expression[Signum]("sign"),
117126
expression[Signum]("signum"),
118127
expression[Sin]("sin"),
119128
expression[Sinh]("sinh"),
120129
expression[Tan]("tan"),
121130
expression[Tanh]("tanh"),
122-
expression[ToDegrees]("todegrees"),
123-
expression[ToRadians]("toradians"),
131+
expression[ToDegrees]("degrees"),
132+
expression[ToRadians]("radians"),
124133

125134
// aggregate functions
126135
expression[Average]("avg"),
@@ -132,10 +141,12 @@ object FunctionRegistry {
132141
expression[Sum]("sum"),
133142

134143
// string functions
144+
expression[Lower]("lcase"),
135145
expression[Lower]("lower"),
136146
expression[StringLength]("length"),
137147
expression[Substring]("substr"),
138148
expression[Substring]("substring"),
149+
expression[Upper]("ucase"),
139150
expression[Upper]("upper")
140151
)
141152

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ object HiveTypeCoercion {
5858
case _ => None
5959
}
6060

61+
/** Similar to [[findTightestCommonType]], but can promote all the way to StringType. */
62+
private def findTightestCommonTypeToString(left: DataType, right: DataType): Option[DataType] = {
63+
findTightestCommonTypeOfTwo(left, right).orElse((left, right) match {
64+
case (StringType, t2: AtomicType) if t2 != BinaryType && t2 != BooleanType => Some(StringType)
65+
case (t1: AtomicType, StringType) if t1 != BinaryType && t1 != BooleanType => Some(StringType)
66+
case _ => None
67+
})
68+
}
69+
6170
/**
6271
* Find the tightest common type of a set of types by continuously applying
6372
* `findTightestCommonTypeOfTwo` on these types.
@@ -91,6 +100,7 @@ trait HiveTypeCoercion {
91100
StringToIntegralCasts ::
92101
FunctionArgumentConversion ::
93102
CaseWhenCoercion ::
103+
IfCoercion ::
94104
Division ::
95105
PropagateTypes ::
96106
ExpectedInputConversion ::
@@ -652,6 +662,26 @@ trait HiveTypeCoercion {
652662
}
653663
}
654664

665+
/**
666+
* Coerces the type of different branches of If statement to a common type.
667+
*/
668+
object IfCoercion extends Rule[LogicalPlan] {
669+
def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
670+
// Find tightest common type for If, if the true value and false value have different types.
671+
case i @ If(pred, left, right) if left.dataType != right.dataType =>
672+
findTightestCommonTypeToString(left.dataType, right.dataType).map { widestType =>
673+
val newLeft = if (left.dataType == widestType) left else Cast(left, widestType)
674+
val newRight = if (right.dataType == widestType) right else Cast(right, widestType)
675+
i.makeCopy(Array(pred, newLeft, newRight))
676+
}.getOrElse(i) // If there is no applicable conversion, leave expression unchanged.
677+
678+
// Convert If(null literal, _, _) into boolean type.
679+
// In the optimizer, we should short-circuit this directly into false value.
680+
case i @ If(pred, left, right) if pred.dataType == NullType =>
681+
i.makeCopy(Array(Literal.create(null, BooleanType), left, right))
682+
}
683+
}
684+
655685
/**
656686
* Casts types according to the expected input types for Expressions that have the trait
657687
* `ExpectsInputTypes`.

0 commit comments

Comments
 (0)