Skip to content

Commit 161d742

Browse files
committed
Merge branch 'master' into SPARK-29688
2 parents 998bd95 + 9562b26 commit 161d742

File tree

85 files changed

+1181
-1147
lines changed

Some content is hidden

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

85 files changed

+1181
-1147
lines changed

.github/workflows/master.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
export MAVEN_OPTS="-Xmx2g -XX:ReservedCodeCacheSize=1g -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN"
3333
export MAVEN_CLI_OPTS="--no-transfer-progress"
34-
./build/mvn $MAVEN_CLI_OPTS -DskipTests -Pyarn -Pmesos -Pkubernetes -Phive -Phive-thriftserver -P${{ matrix.hadoop }} -Phadoop-cloud -Djava.version=${{ matrix.java }} package
34+
./build/mvn $MAVEN_CLI_OPTS -DskipTests -Pyarn -Pmesos -Pkubernetes -Phive -Phive-thriftserver -P${{ matrix.hadoop }} -Phadoop-cloud -Djava.version=${{ matrix.java }} install
3535
3636
3737
lint:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.catalyst.util;
19+
20+
public class DateTimeConstants {
21+
22+
public static final int YEARS_PER_DECADE = 10;
23+
public static final int YEARS_PER_CENTURY = 100;
24+
public static final int YEARS_PER_MILLENNIUM = 1000;
25+
26+
public static final byte MONTHS_PER_QUARTER = 3;
27+
public static final int MONTHS_PER_YEAR = 12;
28+
29+
public static final byte DAYS_PER_WEEK = 7;
30+
public static final long DAYS_PER_MONTH = 30L;
31+
32+
public static final long HOURS_PER_DAY = 24L;
33+
34+
public static final long MINUTES_PER_HOUR = 60L;
35+
36+
public static final long SECONDS_PER_MINUTE = 60L;
37+
public static final long SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
38+
public static final long SECONDS_PER_DAY = HOURS_PER_DAY * SECONDS_PER_HOUR;
39+
40+
public static final long MILLIS_PER_SECOND = 1000L;
41+
public static final long MILLIS_PER_MINUTE = SECONDS_PER_MINUTE * MILLIS_PER_SECOND;
42+
public static final long MILLIS_PER_HOUR = MINUTES_PER_HOUR * MILLIS_PER_MINUTE;
43+
public static final long MILLIS_PER_DAY = HOURS_PER_DAY * MILLIS_PER_HOUR;
44+
45+
public static final long MICROS_PER_MILLIS = 1000L;
46+
public static final long MICROS_PER_SECOND = MILLIS_PER_SECOND * MICROS_PER_MILLIS;
47+
public static final long MICROS_PER_MINUTE = SECONDS_PER_MINUTE * MICROS_PER_SECOND;
48+
public static final long MICROS_PER_HOUR = MINUTES_PER_HOUR * MICROS_PER_MINUTE;
49+
public static final long MICROS_PER_DAY = HOURS_PER_DAY * MICROS_PER_HOUR;
50+
public static final long MICROS_PER_MONTH = DAYS_PER_MONTH * MICROS_PER_DAY;
51+
/* 365.25 days per year assumes leap year every four years */
52+
public static final long MICROS_PER_YEAR = (36525L * MICROS_PER_DAY) / 100;
53+
54+
public static final long NANOS_PER_MICROS = 1000L;
55+
public static final long NANOS_PER_MILLIS = MICROS_PER_MILLIS * NANOS_PER_MICROS;
56+
public static final long NANOS_PER_SECOND = MILLIS_PER_SECOND * NANOS_PER_MILLIS;
57+
}

common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,16 @@
2424
import java.time.temporal.ChronoUnit;
2525
import java.util.Objects;
2626

27+
import static org.apache.spark.sql.catalyst.util.DateTimeConstants.*;
28+
2729
/**
2830
* The internal representation of interval type.
2931
*/
3032
public final class CalendarInterval implements Serializable {
31-
public static final long MICROS_PER_MILLI = 1000L;
32-
public static final long MICROS_PER_SECOND = MICROS_PER_MILLI * 1000;
33-
public static final long MICROS_PER_MINUTE = MICROS_PER_SECOND * 60;
34-
public static final long MICROS_PER_HOUR = MICROS_PER_MINUTE * 60;
35-
public static final long MICROS_PER_DAY = MICROS_PER_HOUR * 24;
36-
public static final long MICROS_PER_WEEK = MICROS_PER_DAY * 7;
37-
3833
public final int months;
3934
public final int days;
4035
public final long microseconds;
4136

42-
public long milliseconds() {
43-
return this.microseconds / MICROS_PER_MILLI;
44-
}
45-
4637
public CalendarInterval(int months, int days, long microseconds) {
4738
this.months = months;
4839
this.days = days;
@@ -84,35 +75,38 @@ public int hashCode() {
8475

8576
@Override
8677
public String toString() {
87-
StringBuilder sb = new StringBuilder("interval");
78+
if (months == 0 && days == 0 && microseconds == 0) {
79+
return "0 seconds";
80+
}
81+
82+
StringBuilder sb = new StringBuilder();
8883

8984
if (months != 0) {
90-
appendUnit(sb, months / 12, "year");
91-
appendUnit(sb, months % 12, "month");
85+
appendUnit(sb, months / 12, "years");
86+
appendUnit(sb, months % 12, "months");
9287
}
9388

94-
appendUnit(sb, days, "day");
89+
appendUnit(sb, days, "days");
9590

9691
if (microseconds != 0) {
9792
long rest = microseconds;
98-
appendUnit(sb, rest / MICROS_PER_HOUR, "hour");
93+
appendUnit(sb, rest / MICROS_PER_HOUR, "hours");
9994
rest %= MICROS_PER_HOUR;
100-
appendUnit(sb, rest / MICROS_PER_MINUTE, "minute");
95+
appendUnit(sb, rest / MICROS_PER_MINUTE, "minutes");
10196
rest %= MICROS_PER_MINUTE;
10297
if (rest != 0) {
10398
String s = BigDecimal.valueOf(rest, 6).stripTrailingZeros().toPlainString();
104-
sb.append(' ').append(s).append(" seconds");
99+
sb.append(s).append(" seconds ");
105100
}
106-
} else if (months == 0 && days == 0) {
107-
sb.append(" 0 microseconds");
108101
}
109102

103+
sb.setLength(sb.length() - 1);
110104
return sb.toString();
111105
}
112106

113107
private void appendUnit(StringBuilder sb, long value, String unit) {
114108
if (value != 0) {
115-
sb.append(' ').append(value).append(' ').append(unit).append('s');
109+
sb.append(value).append(' ').append(unit).append(' ');
116110
}
117111
}
118112

common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private byte getByte(int i) {
370370
return Platform.getByte(base, offset + i);
371371
}
372372

373-
private boolean matchAt(final UTF8String s, int pos) {
373+
public boolean matchAt(final UTF8String s, int pos) {
374374
if (s.numBytes + pos > numBytes || pos < 0) {
375375
return false;
376376
}

common/unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.time.Period;
2424

2525
import static org.junit.Assert.*;
26-
import static org.apache.spark.unsafe.types.CalendarInterval.*;
26+
import static org.apache.spark.sql.catalyst.util.DateTimeConstants.*;
2727

2828
public class CalendarIntervalSuite {
2929

@@ -51,28 +51,28 @@ public void toStringTest() {
5151
CalendarInterval i;
5252

5353
i = new CalendarInterval(0, 0, 0);
54-
assertEquals("interval 0 microseconds", i.toString());
54+
assertEquals("0 seconds", i.toString());
5555

5656
i = new CalendarInterval(34, 0, 0);
57-
assertEquals("interval 2 years 10 months", i.toString());
57+
assertEquals("2 years 10 months", i.toString());
5858

5959
i = new CalendarInterval(-34, 0, 0);
60-
assertEquals("interval -2 years -10 months", i.toString());
60+
assertEquals("-2 years -10 months", i.toString());
6161

6262
i = new CalendarInterval(0, 31, 0);
63-
assertEquals("interval 31 days", i.toString());
63+
assertEquals("31 days", i.toString());
6464

6565
i = new CalendarInterval(0, -31, 0);
66-
assertEquals("interval -31 days", i.toString());
66+
assertEquals("-31 days", i.toString());
6767

6868
i = new CalendarInterval(0, 0, 3 * MICROS_PER_HOUR + 13 * MICROS_PER_MINUTE + 123);
69-
assertEquals("interval 3 hours 13 minutes 0.000123 seconds", i.toString());
69+
assertEquals("3 hours 13 minutes 0.000123 seconds", i.toString());
7070

7171
i = new CalendarInterval(0, 0, -3 * MICROS_PER_HOUR - 13 * MICROS_PER_MINUTE - 123);
72-
assertEquals("interval -3 hours -13 minutes -0.000123 seconds", i.toString());
72+
assertEquals("-3 hours -13 minutes -0.000123 seconds", i.toString());
7373

7474
i = new CalendarInterval(34, 31, 3 * MICROS_PER_HOUR + 13 * MICROS_PER_MINUTE + 123);
75-
assertEquals("interval 2 years 10 months 31 days 3 hours 13 minutes 0.000123 seconds",
75+
assertEquals("2 years 10 months 31 days 3 hours 13 minutes 0.000123 seconds",
7676
i.toString());
7777
}
7878

core/src/main/scala/org/apache/spark/TestUtils.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import java.nio.file.{Files => JavaFiles}
2424
import java.nio.file.attribute.PosixFilePermission.{OWNER_EXECUTE, OWNER_READ, OWNER_WRITE}
2525
import java.security.SecureRandom
2626
import java.security.cert.X509Certificate
27-
import java.util.{Arrays, EnumSet, Properties}
27+
import java.util.{Arrays, EnumSet, Locale, Properties}
2828
import java.util.concurrent.{TimeoutException, TimeUnit}
2929
import java.util.jar.{JarEntry, JarOutputStream, Manifest}
3030
import javax.net.ssl._
@@ -214,12 +214,20 @@ private[spark] object TestUtils {
214214
* Asserts that exception message contains the message. Please note this checks all
215215
* exceptions in the tree.
216216
*/
217-
def assertExceptionMsg(exception: Throwable, msg: String): Unit = {
217+
def assertExceptionMsg(exception: Throwable, msg: String, ignoreCase: Boolean = false): Unit = {
218+
def contain(msg1: String, msg2: String): Boolean = {
219+
if (ignoreCase) {
220+
msg1.toLowerCase(Locale.ROOT).contains(msg2.toLowerCase(Locale.ROOT))
221+
} else {
222+
msg1.contains(msg2)
223+
}
224+
}
225+
218226
var e = exception
219-
var contains = e.getMessage.contains(msg)
227+
var contains = contain(e.getMessage, msg)
220228
while (e.getCause != null && !contains) {
221229
e = e.getCause
222-
contains = e.getMessage.contains(msg)
230+
contains = contain(e.getMessage, msg)
223231
}
224232
assert(contains, s"Exception tree doesn't contain the expected message: $msg")
225233
}

docs/running-on-yarn.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ To use a custom metrics.properties for the application master and executors, upd
419419
in YARN ApplicationReports, which can be used for filtering when querying YARN apps.
420420
</td>
421421
</tr>
422+
<tr>
423+
<td><code>spark.yarn.priority</code></td>
424+
<td>(none)</td>
425+
<td>
426+
Application priority for YARN to define pending applications ordering policy, those with higher
427+
integer value have a better opportunity to be activated. Currently, YARN only supports application
428+
priority when using FIFO ordering policy.
429+
</td>
430+
</tr>
422431
<tr>
423432
<td><code>spark.yarn.config.gatewayPath</code></td>
424433
<td>(none)</td>

docs/sql-migration-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,13 @@ license: |
217217
For example `SELECT timestamp 'tomorrow';`.
218218

219219
- Since Spark 3.0, the `size` function returns `NULL` for the `NULL` input. In Spark version 2.4 and earlier, this function gives `-1` for the same input. To restore the behavior before Spark 3.0, you can set `spark.sql.legacy.sizeOfNull` to `true`.
220+
221+
- Since Spark 3.0, when `array` function is called without parameters, it returns an empty array with `NullType` data type. In Spark version 2.4 and earlier, the data type of the result is `StringType`.
220222

221223
- Since Spark 3.0, the interval literal syntax does not allow multiple from-to units anymore. For example, `SELECT INTERVAL '1-1' YEAR TO MONTH '2-2' YEAR TO MONTH'` throws parser exception.
222224

225+
- Since Spark 3.0, when casting interval values to string type, there is no "interval" prefix, e.g. `1 days 2 hours`. In Spark version 2.4 and earlier, the string contains the "interval" prefix like `interval 1 days 2 hours`.
226+
223227
## Upgrading from Spark SQL 2.4 to 2.4.1
224228

225229
- The value of `spark.executor.heartbeatInterval`, when specified without units like "30" rather than "30s", was

external/avro/src/main/scala/org/apache/spark/sql/avro/AvroDeserializer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import org.apache.avro.util.Utf8
3232

3333
import org.apache.spark.sql.catalyst.InternalRow
3434
import org.apache.spark.sql.catalyst.expressions.{SpecificInternalRow, UnsafeArrayData}
35-
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, ArrayData, DateTimeUtils, GenericArrayData}
35+
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, ArrayData, GenericArrayData}
36+
import org.apache.spark.sql.catalyst.util.DateTimeConstants.MILLIS_PER_DAY
3637
import org.apache.spark.sql.types._
3738
import org.apache.spark.unsafe.types.UTF8String
38-
3939
/**
4040
* A deserializer to deserialize data in avro format to data in catalyst format.
4141
*/
@@ -110,7 +110,7 @@ class AvroDeserializer(rootAvroType: Schema, rootCatalystType: DataType) {
110110
// Before we upgrade Avro to 1.8 for logical type support, spark-avro converts Long to Date.
111111
// For backward compatibility, we still keep this conversion.
112112
case (LONG, DateType) => (updater, ordinal, value) =>
113-
updater.setInt(ordinal, (value.asInstanceOf[Long] / DateTimeUtils.MILLIS_PER_DAY).toInt)
113+
updater.setInt(ordinal, (value.asInstanceOf[Long] / MILLIS_PER_DAY).toInt)
114114

115115
case (FLOAT, FloatType) => (updater, ordinal, value) =>
116116
updater.setFloat(ordinal, value.asInstanceOf[Float])

0 commit comments

Comments
 (0)