Skip to content

Commit 5ccc040

Browse files
authored
Merge pull request apache-spark-on-k8s#358 from palantir/rk/more-upstream
2 parents 18acf6d + 7f5253f commit 5ccc040

File tree

271 files changed

+9917
-4515
lines changed

Some content is hidden

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

271 files changed

+9917
-4515
lines changed

common/unsafe/src/main/java/org/apache/spark/sql/catalyst/expressions/HiveHasher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.spark.sql.catalyst.expressions;
1919

2020
import org.apache.spark.unsafe.memory.MemoryBlock;
21+
import org.apache.spark.unsafe.types.UTF8String;
2122

2223
/**
2324
* Simulates Hive's hashing function from Hive v1.2.1
@@ -51,4 +52,8 @@ public static int hashUnsafeBytesBlock(MemoryBlock mb) {
5152
public static int hashUnsafeBytes(Object base, long offset, int lengthInBytes) {
5253
return hashUnsafeBytesBlock(MemoryBlock.allocateFromObject(base, offset, lengthInBytes));
5354
}
55+
56+
public static int hashUTF8String(UTF8String str) {
57+
return hashUnsafeBytesBlock(str.getMemoryBlock());
58+
}
5459
}

common/unsafe/src/main/java/org/apache/spark/unsafe/hash/Murmur3_x86_32.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.primitives.Ints;
2121

2222
import org.apache.spark.unsafe.memory.MemoryBlock;
23+
import org.apache.spark.unsafe.types.UTF8String;
2324

2425
/**
2526
* 32-bit Murmur3 hasher. This is based on Guava's Murmur3_32HashFunction.
@@ -82,6 +83,10 @@ public static int hashUnsafeBytesBlock(MemoryBlock base, int seed) {
8283
return fmix(h1, lengthInBytes);
8384
}
8485

86+
public static int hashUTF8String(UTF8String str, int seed) {
87+
return hashUnsafeBytesBlock(str.getMemoryBlock(), seed);
88+
}
89+
8590
public static int hashUnsafeBytes(Object base, long offset, int lengthInBytes, int seed) {
8691
return hashUnsafeBytesBlock(MemoryBlock.allocateFromObject(base, offset, lengthInBytes), seed);
8792
}
@@ -91,7 +96,7 @@ public static int hashUnsafeBytes2(Object base, long offset, int lengthInBytes,
9196
}
9297

9398
public static int hashUnsafeBytes2Block(MemoryBlock base, int seed) {
94-
// This is compatible with original and another implementations.
99+
// This is compatible with original and other implementations.
95100
// Use this method for new components after Spark 2.3.
96101
int lengthInBytes = Ints.checkedCast(base.size());
97102
assert (lengthInBytes >= 0) : "lengthInBytes cannot be negative";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ private static void checkBasic(String str, int len) {
5252

5353
assertTrue(s1.contains(s2));
5454
assertTrue(s2.contains(s1));
55-
assertTrue(s1.startsWith(s1));
56-
assertTrue(s1.endsWith(s1));
55+
assertTrue(s1.startsWith(s2));
56+
assertTrue(s1.endsWith(s2));
5757
}
5858

5959
@Test

common/unsafe/src/test/scala/org/apache/spark/unsafe/types/UTF8StringPropertyCheckSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class UTF8StringPropertyCheckSuite extends FunSuite with GeneratorDrivenProperty
164164
def padding(origin: String, pad: String, length: Int, isLPad: Boolean): String = {
165165
if (length <= 0) return ""
166166
if (length <= origin.length) {
167-
if (length <= 0) "" else origin.substring(0, length)
167+
origin.substring(0, length)
168168
} else {
169169
if (pad.length == 0) return origin
170170
val toPad = length - origin.length

core/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeInMemorySorter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public UnsafeInMemorySorter(
124124
int initialSize,
125125
boolean canUseRadixSort) {
126126
this(consumer, memoryManager, recordComparator, prefixComparator,
127-
consumer.allocateArray(initialSize * 2), canUseRadixSort);
127+
consumer.allocateArray(initialSize * 2L), canUseRadixSort);
128128
}
129129

130130
public UnsafeInMemorySorter(

core/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeSortDataFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void copyRange(LongArray src, int srcPos, LongArray dst, int dstPos, int
8484

8585
@Override
8686
public LongArray allocate(int length) {
87-
assert (length * 2 <= buffer.size()) :
87+
assert (length * 2L <= buffer.size()) :
8888
"the buffer is smaller than required: " + buffer.size() + " < " + (length * 2);
8989
return buffer;
9090
}

core/src/main/scala/org/apache/spark/deploy/DependencyUtils.scala

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import org.apache.hadoop.conf.Configuration
2525
import org.apache.hadoop.fs.{FileSystem, Path}
2626

2727
import org.apache.spark.{SecurityManager, SparkConf, SparkException}
28+
import org.apache.spark.internal.Logging
2829
import org.apache.spark.util.{MutableURLClassLoader, Utils}
2930

30-
private[deploy] object DependencyUtils {
31+
private[deploy] object DependencyUtils extends Logging {
3132

3233
def resolveMavenDependencies(
3334
packagesExclusions: String,
@@ -75,7 +76,7 @@ private[deploy] object DependencyUtils {
7576
def addJarsToClassPath(jars: String, loader: MutableURLClassLoader): Unit = {
7677
if (jars != null) {
7778
for (jar <- jars.split(",")) {
78-
SparkSubmit.addJarToClasspath(jar, loader)
79+
addJarToClasspath(jar, loader)
7980
}
8081
}
8182
}
@@ -151,6 +152,31 @@ private[deploy] object DependencyUtils {
151152
}.mkString(",")
152153
}
153154

155+
def addJarToClasspath(localJar: String, loader: MutableURLClassLoader): Unit = {
156+
val uri = Utils.resolveURI(localJar)
157+
uri.getScheme match {
158+
case "file" | "local" =>
159+
val file = new File(uri.getPath)
160+
if (file.exists()) {
161+
loader.addURL(file.toURI.toURL)
162+
} else {
163+
logWarning(s"Local jar $file does not exist, skipping.")
164+
}
165+
case _ =>
166+
logWarning(s"Skip remote jar $uri.")
167+
}
168+
}
169+
170+
/**
171+
* Merge a sequence of comma-separated file lists, some of which may be null to indicate
172+
* no files, into a single comma-separated string.
173+
*/
174+
def mergeFileLists(lists: String*): String = {
175+
val merged = lists.filterNot(StringUtils.isBlank)
176+
.flatMap(Utils.stringToSeq)
177+
if (merged.nonEmpty) merged.mkString(",") else null
178+
}
179+
154180
private def splitOnFragment(path: String): (URI, Option[String]) = {
155181
val uri = Utils.resolveURI(path)
156182
val withoutFragment = new URI(uri.getScheme, uri.getSchemeSpecificPart, null)

0 commit comments

Comments
 (0)