forked from delta-io/delta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
1731 lines (1604 loc) · 72.7 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (2021) The Delta Lake Project Authors.
*
* Licensed 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.
*/
// scalastyle:off line.size.limit
import java.io.BufferedInputStream
import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermission
import java.util
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
import org.apache.commons.compress.utils.IOUtils
import scala.collection.mutable
import scala.sys.process._
import scala.util.Using
import sbt.internal.inc.Analysis
import sbtprotoc.ProtocPlugin.autoImport._
import xsbti.compile.CompileAnalysis
import Checkstyle._
import Mima._
import Unidoc._
// Scala versions
val scala212 = "2.12.18"
val scala213 = "2.13.13"
val all_scala_versions = Seq(scala212, scala213)
// Due to how publishArtifact is determined for javaOnlyReleaseSettings, incl. storage
// It was necessary to change default_scala_version to scala213 in build.sbt
// to build the project with Scala 2.13 only
// As a setting, it's possible to set it on command line easily
// sbt 'set default_scala_version := 2.13.13' [commands]
// FIXME Why not use scalaVersion?
val default_scala_version = settingKey[String]("Default Scala version")
Global / default_scala_version := scala212
val LATEST_RELEASED_SPARK_VERSION = "3.5.2"
val SPARK_MASTER_VERSION = "4.0.0-SNAPSHOT"
val sparkVersion = settingKey[String]("Spark version")
spark / sparkVersion := getSparkVersion()
connectCommon / sparkVersion := getSparkVersion()
connectClient / sparkVersion := getSparkVersion()
connectServer / sparkVersion := getSparkVersion()
sharing / sparkVersion := getSparkVersion()
// Dependent library versions
val defaultSparkVersion = LATEST_RELEASED_SPARK_VERSION
val flinkVersion = "1.16.1"
val hadoopVersion = "3.3.4"
val scalaTestVersion = "3.2.15"
val scalaTestVersionForConnectors = "3.0.8"
val parquet4sVersion = "1.9.4"
// Versions for Hive 3
val hadoopVersionForHive3 = "3.1.0"
val hiveVersion = "3.1.2"
val tezVersion = "0.9.2"
// Versions for Hive 2
val hadoopVersionForHive2 = "2.7.2"
val hive2Version = "2.3.3"
val tezVersionForHive2 = "0.8.4"
val protoVersion = "3.25.1"
val grpcVersion = "1.62.2"
scalaVersion := default_scala_version.value
// crossScalaVersions must be set to Nil on the root project
crossScalaVersions := Nil
// For Java 11 use the following on command line
// sbt 'set targetJvm := "11"' [commands]
val targetJvm = settingKey[String]("Target JVM version")
Global / targetJvm := "8"
lazy val javaVersion = sys.props.getOrElse("java.version", "Unknown")
/**
* Returns the current spark version, which is the same value as `sparkVersion.value`.
*
* This logic exists in a separate method because some call sites cannot access `sparkVersion.value`
* e.g. callers that are not inside tasks or setting macros.
*/
def getSparkVersion(): String = {
val latestReleasedSparkVersionShort = getMajorMinorPatch(LATEST_RELEASED_SPARK_VERSION) match {
case (maj, min, _) => s"$maj.$min"
}
val allValidSparkVersionInputs = Seq(
"master",
"latest",
SPARK_MASTER_VERSION,
LATEST_RELEASED_SPARK_VERSION,
latestReleasedSparkVersionShort
)
// e.g. build/sbt -DsparkVersion=master, build/sbt -DsparkVersion=4.0.0-SNAPSHOT
val input = sys.props.getOrElse("sparkVersion", LATEST_RELEASED_SPARK_VERSION)
input match {
case LATEST_RELEASED_SPARK_VERSION | "latest" | `latestReleasedSparkVersionShort` =>
LATEST_RELEASED_SPARK_VERSION
case SPARK_MASTER_VERSION | "master" =>
SPARK_MASTER_VERSION
case _ =>
throw new IllegalArgumentException(s"Invalid sparkVersion: $input. Must be one of " +
s"${allValidSparkVersionInputs.mkString("{", ",", "}")}")
}
}
lazy val commonSettings = Seq(
organization := "io.delta",
scalaVersion := default_scala_version.value,
crossScalaVersions := all_scala_versions,
fork := true,
scalacOptions ++= Seq("-Ywarn-unused:imports"),
javacOptions ++= {
if (javaVersion.startsWith("1.8")) {
Seq.empty // `--release` is supported since JDK 9 and the minimum supported JDK is 8
} else {
Seq("--release", targetJvm.value) // generated bytecode should be usable with JVM 1.8
}
},
// Make sure any tests in any project that uses Spark is configured for running well locally
Test / javaOptions ++= Seq(
"-Dspark.ui.enabled=false",
"-Dspark.ui.showConsoleProgress=false",
"-Dspark.databricks.delta.snapshotPartitions=2",
"-Dspark.sql.shuffle.partitions=5",
"-Ddelta.log.cacheSize=3",
"-Dspark.databricks.delta.delta.log.cacheSize=3",
"-Dspark.sql.sources.parallelPartitionDiscovery.parallelism=5",
"-Xmx1024m"
),
testOptions += Tests.Argument("-oF"),
// Unidoc settings: by default dont document any source file
unidocSourceFilePatterns := Nil,
)
// enforce java code style
def javafmtCheckSettings() = Seq(
(Compile / compile) := ((Compile / compile) dependsOn (Compile / javafmtCheckAll)).value
)
/**
* Note: we cannot access sparkVersion.value here, since that can only be used within a task or
* setting macro.
*/
def crossSparkSettings(): Seq[Setting[_]] = getSparkVersion() match {
case LATEST_RELEASED_SPARK_VERSION => Seq(
scalaVersion := default_scala_version.value,
crossScalaVersions := all_scala_versions,
targetJvm := "8",
// For adding staged Spark RC versions, e.g.:
// resolvers += "Apache Spark 3.5.0 (RC1) Staging" at "https://repository.apache.org/content/repositories/orgapachespark-1444/",
Compile / unmanagedSourceDirectories += (Compile / baseDirectory).value / "src" / "main" / "scala-spark-3.5",
Test / unmanagedSourceDirectories += (Test / baseDirectory).value / "src" / "test" / "scala-spark-3.5",
Antlr4 / antlr4Version := "4.9.3",
// Java-/Scala-/Uni-Doc Settings
scalacOptions ++= Seq(
"-P:genjavadoc:strictVisibility=true" // hide package private types and methods in javadoc
),
unidocSourceFilePatterns := Seq(SourceFilePattern("io/delta/tables/", "io/delta/exceptions/"))
)
case SPARK_MASTER_VERSION => Seq(
scalaVersion := scala213,
crossScalaVersions := Seq(scala213),
targetJvm := "17",
resolvers += "Spark master staging" at "https://repository.apache.org/content/groups/snapshots/",
Compile / unmanagedSourceDirectories += (Compile / baseDirectory).value / "src" / "main" / "scala-spark-master",
Test / unmanagedSourceDirectories += (Test / baseDirectory).value / "src" / "test" / "scala-spark-master",
Antlr4 / antlr4Version := "4.13.1",
Test / javaOptions ++= Seq(
// Copied from SparkBuild.scala to support Java 17 for unit tests (see apache/spark#34153)
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens=java.base/java.io=ALL-UNNAMED",
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.cs=ALL-UNNAMED",
"--add-opens=java.base/sun.security.action=ALL-UNNAMED",
"--add-opens=java.base/sun.util.calendar=ALL-UNNAMED"
)
// Java-/Scala-/Uni-Doc Settings
// This isn't working yet against Spark Master.
// 1) delta-spark on Spark Master uses JDK 17. delta-iceberg uses JDK 8 or 11. For some reason,
// generating delta-spark unidoc compiles delta-iceberg
// 2) delta-spark unidoc fails to compile. spark 3.5 is on its classpath. likely due to iceberg
// issue above.
)
}
def runTaskOnlyOnSparkMaster[T](
task: sbt.TaskKey[T],
taskName: String,
projectName: String,
emptyValue: => T): Def.Initialize[Task[T]] = {
if (getSparkVersion() == SPARK_MASTER_VERSION) {
Def.task(task.value)
} else {
Def.task {
// scalastyle:off println
println(s"Project $projectName: Skipping `$taskName` as Spark version " +
s"${getSparkVersion()} does not equal $SPARK_MASTER_VERSION.")
// scalastyle:on println
emptyValue
}
}
}
lazy val connectCommon = (project in file("spark-connect/common"))
.disablePlugins(JavaFormatterPlugin)
.settings(
name := "delta-connect-common",
commonSettings,
crossSparkSettings(),
releaseSettings,
Compile / compile := runTaskOnlyOnSparkMaster(
task = Compile / compile,
taskName = "compile",
projectName = "delta-connect-common",
emptyValue = Analysis.empty.asInstanceOf[CompileAnalysis]
).value,
Test / test := runTaskOnlyOnSparkMaster(
task = Test / test,
taskName = "test",
projectName = "delta-connect-common",
emptyValue = ()).value,
publish := runTaskOnlyOnSparkMaster(
task = publish,
taskName = "publish",
projectName = "delta-connect-common",
emptyValue = ()).value,
libraryDependencies ++= Seq(
"io.grpc" % "protoc-gen-grpc-java" % grpcVersion asProtocPlugin(),
"io.grpc" % "grpc-protobuf" % grpcVersion,
"io.grpc" % "grpc-stub" % grpcVersion,
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf",
"javax.annotation" % "javax.annotation-api" % "1.3.2",
"org.apache.spark" %% "spark-connect-common" % sparkVersion.value % "provided",
),
PB.protocVersion := protoVersion,
Compile / PB.targets := Seq(
PB.gens.java -> (Compile / sourceManaged).value,
PB.gens.plugin("grpc-java") -> (Compile / sourceManaged).value
),
)
lazy val connectClient = (project in file("spark-connect/client"))
.disablePlugins(JavaFormatterPlugin)
.dependsOn(connectCommon % "compile->compile;test->test;provided->provided")
.settings(
name := "delta-connect-client",
commonSettings,
releaseSettings,
Compile / compile := runTaskOnlyOnSparkMaster(
task = Compile / compile,
taskName = "compile",
projectName = "delta-connect-client",
emptyValue = Analysis.empty.asInstanceOf[CompileAnalysis]
).value,
Test / test := runTaskOnlyOnSparkMaster(
task = Test / test,
taskName = "test",
projectName = "delta-connect-client",
emptyValue = ()
).value,
publish := runTaskOnlyOnSparkMaster(
task = publish,
taskName = "publish",
projectName = "delta-connect-client",
emptyValue = ()
).value,
crossSparkSettings(),
libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf",
"org.apache.spark" %% "spark-connect-client-jvm" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-connect" % sparkVersion.value % "provided",
// Test deps
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.apache.spark" %% "spark-common-utils" % sparkVersion.value % "test",
"org.apache.spark" %% "spark-connect-client-jvm" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-connect" % sparkVersion.value % "test" classifier "tests",
),
(Test / javaOptions) += s"-Ddelta.test.home=" + file(".").getAbsoluteFile.getParentFile,
(Test / resourceGenerators) += Def.task {
val location = url("https://dist.apache.org/repos/dist/release/spark/spark-4.0.0-preview1/spark-4.0.0-preview1-bin-hadoop3.tgz")
val destDir = (Test / resourceManaged).value / "spark"
if (!destDir.exists()) {
IO.createDirectory(destDir)
val files = mutable.Buffer.empty[File]
Using(new BufferedInputStream(location.openStream())) { bi =>
Using(new GzipCompressorInputStream(bi)) { gi =>
Using(new TarArchiveInputStream(gi)) { ti =>
var entry = ti.getNextEntry
while (entry != null) {
val dest = destDir / entry.getName
if (entry.isDirectory) {
dest.mkdirs()
} else {
files += dest
Using(Files.newOutputStream(dest.toPath)) { os =>
IOUtils.copy(ti, os)
}
val perms = new util.HashSet[PosixFilePermission]()
perms.add(PosixFilePermission.OWNER_EXECUTE)
perms.add(PosixFilePermission.OWNER_READ)
perms.add(PosixFilePermission.OWNER_WRITE)
Files.setPosixFilePermissions(dest.toPath, perms)
}
entry = ti.getNextEntry
}
}
}
}
files
} else {
destDir.get()
}
}.taskValue,
(Test / resourceGenerators) += Def.task {
val src = url("https://repository.apache.org/content/groups/public/org/apache/spark/spark-connect_2.13/4.0.0-preview1/spark-connect_2.13-4.0.0-preview1.jar")
val dest = (Test / resourceManaged).value / "spark-connect.jar"
if (!dest.exists()) {
src #> dest !;
Seq(dest)
} else {
dest.get()
}
}.taskValue
)
lazy val connectServer = (project in file("spark-connect/server"))
.dependsOn(connectCommon % "compile->compile;test->test;provided->provided")
.dependsOn(spark % "compile->compile;test->test;provided->provided")
.disablePlugins(JavaFormatterPlugin)
.settings(
name := "delta-connect-server",
commonSettings,
releaseSettings,
Compile / compile := runTaskOnlyOnSparkMaster(
task = Compile / compile,
taskName = "compile",
projectName = "delta-connect-server",
emptyValue = Analysis.empty.asInstanceOf[CompileAnalysis]
).value,
Test / test := runTaskOnlyOnSparkMaster(
task = Test / test,
taskName = "test",
projectName = "delta-connect-server",
emptyValue = ()
).value,
publish := runTaskOnlyOnSparkMaster(
task = publish,
taskName = "publish",
projectName = "delta-connect-server",
emptyValue = ()
).value,
crossSparkSettings(),
libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java" % protoVersion % "protobuf",
"org.apache.spark" %% "spark-hive" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-sql" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-connect" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-sql" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-hive" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-connect" % sparkVersion.value % "test" classifier "tests",
),
)
lazy val spark = (project in file("spark"))
.dependsOn(storage)
.enablePlugins(Antlr4Plugin)
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-spark",
commonSettings,
scalaStyleSettings,
sparkMimaSettings,
releaseSettings,
crossSparkSettings(),
libraryDependencies ++= Seq(
// Adding test classifier seems to break transitive resolution of the core dependencies
"org.apache.spark" %% "spark-hive" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-sql" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "provided",
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value % "provided",
// For DynamoDBCommitStore
"com.amazonaws" % "aws-java-sdk" % "1.12.262" % "provided",
// Test deps
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.9.0" % "test",
"junit" % "junit" % "4.13.2" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test",
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-sql" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-hive" % sparkVersion.value % "test" classifier "tests",
),
Compile / packageBin / mappings := (Compile / packageBin / mappings).value ++
listPythonFiles(baseDirectory.value.getParentFile / "python"),
Antlr4 / antlr4PackageName := Some("io.delta.sql.parser"),
Antlr4 / antlr4GenListener := true,
Antlr4 / antlr4GenVisitor := true,
Test / testOptions += Tests.Argument("-oDF"),
Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a"),
// Don't execute in parallel since we can't have multiple Sparks in the same JVM
Test / parallelExecution := false,
javaOptions += "-Xmx1024m",
// Configurations to speed up tests and reduce memory footprint
Test / javaOptions ++= Seq(
"-Dspark.ui.enabled=false",
"-Dspark.ui.showConsoleProgress=false",
"-Dspark.databricks.delta.snapshotPartitions=2",
"-Dspark.sql.shuffle.partitions=5",
"-Ddelta.log.cacheSize=3",
"-Dspark.databricks.delta.delta.log.cacheSize=3",
"-Dspark.sql.sources.parallelPartitionDiscovery.parallelism=5",
"-Xmx1024m"
),
// Required for testing table features see https://github.com/delta-io/delta/issues/1602
Test / envVars += ("DELTA_TESTING", "1"),
// Hack to avoid errors related to missing repo-root/target/scala-2.12/classes/
createTargetClassesDir := {
val dir = baseDirectory.value.getParentFile / "target" / "scala-2.12" / "classes"
Files.createDirectories(dir.toPath)
},
Compile / compile := ((Compile / compile) dependsOn createTargetClassesDir).value,
// Generate the package object to provide the version information in runtime.
Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "io" / "delta" / "package.scala"
IO.write(file,
s"""package io
|
|package object delta {
| val VERSION = "${version.value}"
|}
|""".stripMargin)
Seq(file)
},
TestParallelization.settings,
)
.configureUnidoc(
generatedJavaDoc = getSparkVersion() == LATEST_RELEASED_SPARK_VERSION,
generateScalaDoc = getSparkVersion() == LATEST_RELEASED_SPARK_VERSION,
// spark-connect has classes with the same name as spark-core, this causes compilation issues
// with unidoc since it concatenates the classpaths from all modules
// ==> thus we exclude such sources
// (mostly) relevant github issue: https://github.com/sbt/sbt-unidoc/issues/77
classPathToSkip = "spark-connect"
)
lazy val contribs = (project in file("contribs"))
.dependsOn(spark % "compile->compile;test->test;provided->provided")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-contribs",
commonSettings,
scalaStyleSettings,
releaseSettings,
Compile / packageBin / mappings := (Compile / packageBin / mappings).value ++
listPythonFiles(baseDirectory.value.getParentFile / "python"),
Test / testOptions += Tests.Argument("-oDF"),
Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a"),
// Don't execute in parallel since we can't have multiple Sparks in the same JVM
Test / parallelExecution := false,
javaOptions += "-Xmx1024m",
// Configurations to speed up tests and reduce memory footprint
Test / javaOptions ++= Seq(
"-Dspark.ui.enabled=false",
"-Dspark.ui.showConsoleProgress=false",
"-Dspark.databricks.delta.snapshotPartitions=2",
"-Dspark.sql.shuffle.partitions=5",
"-Ddelta.log.cacheSize=3",
"-Dspark.databricks.delta.delta.log.cacheSize=3",
"-Dspark.sql.sources.parallelPartitionDiscovery.parallelism=5",
"-Xmx1024m"
),
// Hack to avoid errors related to missing repo-root/target/scala-2.12/classes/
createTargetClassesDir := {
val dir = baseDirectory.value.getParentFile / "target" / "scala-2.12" / "classes"
Files.createDirectories(dir.toPath)
},
Compile / compile := ((Compile / compile) dependsOn createTargetClassesDir).value
).configureUnidoc()
lazy val sharing = (project in file("sharing"))
.dependsOn(spark % "compile->compile;test->test;provided->provided")
.disablePlugins(JavaFormatterPlugin)
.settings(
name := "delta-sharing-spark",
commonSettings,
scalaStyleSettings,
releaseSettings,
crossSparkSettings(),
Test / javaOptions ++= Seq("-ea"),
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-sql" % sparkVersion.value % "provided",
"io.delta" %% "delta-sharing-client" % "1.2.0",
// Test deps
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.9.0" % "test",
"junit" % "junit" % "4.13.2" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test",
"org.apache.spark" %% "spark-catalyst" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-core" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-sql" % sparkVersion.value % "test" classifier "tests",
"org.apache.spark" %% "spark-hive" % sparkVersion.value % "test" classifier "tests",
)
).configureUnidoc()
lazy val kernelApi = (project in file("kernel/kernel-api"))
.settings(
name := "delta-kernel-api",
commonSettings,
scalaStyleSettings,
javaOnlyReleaseSettings,
javafmtCheckSettings,
Test / javaOptions ++= Seq("-ea"),
libraryDependencies ++= Seq(
"org.roaringbitmap" % "RoaringBitmap" % "0.9.25",
"org.slf4j" % "slf4j-api" % "1.7.36",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.13.5",
"com.fasterxml.jackson.core" % "jackson-core" % "2.13.5",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.13.5",
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"junit" % "junit" % "4.13.2" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test",
"org.slf4j" % "slf4j-log4j12" % "1.7.36" % "test",
"org.assertj" % "assertj-core" % "3.26.3" % "test"
),
// Shade jackson libraries so that connector developers don't have to worry
// about jackson version conflicts.
Compile / packageBin := assembly.value,
assembly / assemblyJarName := s"${name.value}-${version.value}.jar",
assembly / logLevel := Level.Info,
assembly / test := {},
assembly / assemblyExcludedJars := {
val cp = (assembly / fullClasspath).value
val allowedPrefixes = Set("META_INF", "io", "jackson")
cp.filter { f =>
!allowedPrefixes.exists(prefix => f.data.getName.startsWith(prefix))
}
},
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("com.fasterxml.jackson.**" -> "io.delta.kernel.shaded.com.fasterxml.jackson.@1").inAll
),
assembly / assemblyMergeStrategy := {
// Discard `module-info.class` to fix the `different file contents found` error.
// TODO Upgrade SBT to 1.5 which will do this automatically
case "module-info.class" => MergeStrategy.discard
case PathList("META-INF", "services", xs @ _*) => MergeStrategy.discard
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
},
// Generate the package object to provide the version information in runtime.
Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "io" / "delta" / "kernel" / "Meta.java"
IO.write(file,
s"""/*
| * Copyright (2024) The Delta Lake Project Authors.
| *
| * Licensed 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 io.delta.kernel;
|
|public final class Meta {
| public static final String KERNEL_VERSION = "${version.value}";
|}
|""".stripMargin)
Seq(file)
},
javaCheckstyleSettings("dev/kernel-checkstyle.xml"),
// Unidoc settings
unidocSourceFilePatterns := Seq(SourceFilePattern("io/delta/kernel/")),
).configureUnidoc(docTitle = "Delta Kernel")
lazy val kernelDefaults = (project in file("kernel/kernel-defaults"))
.dependsOn(kernelApi)
.dependsOn(kernelApi % "test->test")
.dependsOn(storage)
.dependsOn(storage % "test->test") // Required for InMemoryCommitCoordinator for tests
.dependsOn(spark % "test->test")
.dependsOn(goldenTables % "test")
.settings(
name := "delta-kernel-defaults",
commonSettings,
scalaStyleSettings,
javaOnlyReleaseSettings,
javafmtCheckSettings,
Test / javaOptions ++= Seq("-ea"),
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-client-runtime" % hadoopVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % "2.13.5",
"org.apache.parquet" % "parquet-hadoop" % "1.12.3",
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"junit" % "junit" % "4.13.2" % "test",
"commons-io" % "commons-io" % "2.8.0" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test",
"org.slf4j" % "slf4j-log4j12" % "1.7.36" % "test",
// JMH dependencies allow writing micro-benchmarks for testing performance of components.
// JMH has framework to define benchmarks and takes care of many common functionalities
// such as warm runs, cold runs, defining benchmark parameter variables etc.
"org.openjdk.jmh" % "jmh-core" % "1.37" % "test",
"org.openjdk.jmh" % "jmh-generator-annprocess" % "1.37" % "test",
"org.apache.spark" %% "spark-hive" % defaultSparkVersion % "test" classifier "tests",
"org.apache.spark" %% "spark-sql" % defaultSparkVersion % "test" classifier "tests",
"org.apache.spark" %% "spark-core" % defaultSparkVersion % "test" classifier "tests",
"org.apache.spark" %% "spark-catalyst" % defaultSparkVersion % "test" classifier "tests",
),
javaCheckstyleSettings("dev/kernel-checkstyle.xml"),
// Unidoc settings
unidocSourceFilePatterns += SourceFilePattern("io/delta/kernel/"),
).configureUnidoc(docTitle = "Delta Kernel Defaults")
// TODO javastyle tests
// TODO unidoc
// TODO(scott): figure out a better way to include tests in this project
lazy val storage = (project in file("storage"))
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-storage",
commonSettings,
javaOnlyReleaseSettings,
libraryDependencies ++= Seq(
// User can provide any 2.x or 3.x version. We don't use any new fancy APIs. Watch out for
// versions with known vulnerabilities.
"org.apache.hadoop" % "hadoop-common" % hadoopVersion % "provided",
// Note that the org.apache.hadoop.fs.s3a.Listing::createFileStatusListingIterator 3.3.1 API
// is not compatible with 3.3.2.
"org.apache.hadoop" % "hadoop-aws" % hadoopVersion % "provided",
// Test Deps
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
),
// Unidoc settings
unidocSourceFilePatterns += SourceFilePattern("/LogStore.java", "/CloseableIterator.java"),
).configureUnidoc()
lazy val storageS3DynamoDB = (project in file("storage-s3-dynamodb"))
.dependsOn(storage % "compile->compile;test->test;provided->provided")
.dependsOn(spark % "test->test")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-storage-s3-dynamodb",
commonSettings,
javaOnlyReleaseSettings,
// uncomment only when testing FailingS3DynamoDBLogStore. this will include test sources in
// a separate test jar.
// Test / publishArtifact := true,
libraryDependencies ++= Seq(
"com.amazonaws" % "aws-java-sdk" % "1.12.262" % "provided",
// Test Deps
"org.apache.hadoop" % "hadoop-aws" % hadoopVersion % "test", // RemoteFileChangedException
)
).configureUnidoc()
val icebergSparkRuntimeArtifactName = {
val (expMaj, expMin, _) = getMajorMinorPatch(defaultSparkVersion)
s"iceberg-spark-runtime-$expMaj.$expMin"
}
lazy val testDeltaIcebergJar = (project in file("testDeltaIcebergJar"))
// delta-iceberg depends on delta-spark! So, we need to include it during our test.
.dependsOn(spark % "test")
.disablePlugins(JavaFormatterPlugin)
.settings(
name := "test-delta-iceberg-jar",
commonSettings,
skipReleaseSettings,
exportJars := true,
Compile / unmanagedJars += (iceberg / assembly).value,
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-client" % hadoopVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.apache.spark" %% "spark-core" % defaultSparkVersion % "test"
)
)
val deltaIcebergSparkIncludePrefixes = Seq(
// We want everything from this package
"org/apache/spark/sql/delta/icebergShaded",
// We only want the files in this project from this package. e.g. we want to exclude
// org/apache/spark/sql/delta/commands/convert/ConvertTargetFile.class (from delta-spark project).
"org/apache/spark/sql/delta/commands/convert/IcebergFileManifest",
"org/apache/spark/sql/delta/commands/convert/IcebergSchemaUtils",
"org/apache/spark/sql/delta/commands/convert/IcebergTable"
)
// Build using: build/sbt clean icebergShaded/compile iceberg/compile
// It will fail the first time, just re-run it.
// scalastyle:off println
lazy val iceberg = (project in file("iceberg"))
.dependsOn(spark % "compile->compile;test->test;provided->provided")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-iceberg",
commonSettings,
scalaStyleSettings,
releaseSettings,
libraryDependencies ++= Seq(
// Fix Iceberg's legacy java.lang.NoClassDefFoundError: scala/jdk/CollectionConverters$ error
// due to legacy scala.
"org.scala-lang.modules" %% "scala-collection-compat" % "2.1.1",
"org.apache.iceberg" %% icebergSparkRuntimeArtifactName % "1.4.0" % "provided",
"com.github.ben-manes.caffeine" % "caffeine" % "2.9.3"
),
Compile / unmanagedJars += (icebergShaded / assembly).value,
// Generate the assembly JAR as the package JAR
Compile / packageBin := assembly.value,
assembly / assemblyJarName := s"${name.value}_${scalaBinaryVersion.value}-${version.value}.jar",
assembly / logLevel := Level.Info,
assembly / test := {},
assembly / assemblyExcludedJars := {
// Note: the input here is only `libraryDependencies` jars, not `.dependsOn(_)` jars.
val allowedJars = Seq(
s"iceberg-shaded_${scalaBinaryVersion.value}-${version.value}.jar",
s"scala-library-${scala212}.jar",
s"scala-library-${scala213}.jar",
s"scala-collection-compat_${scalaBinaryVersion.value}-2.1.1.jar",
"caffeine-2.9.3.jar",
// Note: We are excluding
// - antlr4-runtime-4.9.3.jar
// - checker-qual-3.19.0.jar
// - error_prone_annotations-2.10.0.jar
)
val cp = (assembly / fullClasspath).value
// Return `true` when we want the jar `f` to be excluded from the assembly jar
cp.filter { f =>
val doExclude = !allowedJars.contains(f.data.getName)
println(s"Excluding jar: ${f.data.getName} ? $doExclude")
doExclude
}
},
assembly / assemblyMergeStrategy := {
// Project iceberg `dependsOn` spark and accidentally brings in it, along with its
// compile-time dependencies (like delta-storage). We want these excluded from the
// delta-iceberg jar.
case PathList("io", "delta", xs @ _*) =>
// - delta-storage will bring in classes: io/delta/storage
// - delta-spark will bring in classes: io/delta/exceptions/, io/delta/implicits,
// io/delta/package, io/delta/sql, io/delta/tables,
MergeStrategy.discard
case PathList("com", "databricks", xs @ _*) =>
// delta-spark will bring in com/databricks/spark/util
MergeStrategy.discard
case PathList("org", "apache", "spark", xs @ _*)
if !deltaIcebergSparkIncludePrefixes.exists { prefix =>
s"org/apache/spark/${xs.mkString("/")}".startsWith(prefix) } =>
MergeStrategy.discard
case PathList("scoverage", xs @ _*) =>
MergeStrategy.discard
case x =>
(assembly / assemblyMergeStrategy).value(x)
},
assemblyPackageScala / assembleArtifact := false
)
// scalastyle:on println
lazy val generateIcebergJarsTask = TaskKey[Unit]("generateIcebergJars", "Generate Iceberg JARs")
lazy val icebergShaded = (project in file("icebergShaded"))
.dependsOn(spark % "provided")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "iceberg-shaded",
commonSettings,
skipReleaseSettings,
// Compile, patch and generated Iceberg JARs
generateIcebergJarsTask := {
import sys.process._
val scriptPath = baseDirectory.value / "generate_iceberg_jars.py"
// Download iceberg code in `iceberg_src` dir and generate the JARs in `lib` dir
Seq("python3", scriptPath.getPath)!
},
Compile / unmanagedJars := (Compile / unmanagedJars).dependsOn(generateIcebergJarsTask).value,
cleanFiles += baseDirectory.value / "iceberg_src",
cleanFiles += baseDirectory.value / "lib",
// Generated shaded Iceberg JARs
Compile / packageBin := assembly.value,
assembly / assemblyJarName := s"${name.value}_${scalaBinaryVersion.value}-${version.value}.jar",
assembly / logLevel := Level.Info,
assembly / test := {},
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("org.apache.iceberg.**" -> "shadedForDelta.@0").inAll,
),
assemblyPackageScala / assembleArtifact := false,
// Make the 'compile' invoke the 'assembly' task to generate the uber jar.
)
lazy val hudi = (project in file("hudi"))
.dependsOn(spark % "compile->compile;test->test;provided->provided")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-hudi",
commonSettings,
scalaStyleSettings,
releaseSettings,
libraryDependencies ++= Seq(
"org.apache.hudi" % "hudi-java-client" % "0.15.0" % "compile" excludeAll(
ExclusionRule(organization = "org.apache.hadoop"),
ExclusionRule(organization = "org.apache.zookeeper"),
),
"org.apache.spark" %% "spark-avro" % defaultSparkVersion % "test" excludeAll ExclusionRule(organization = "org.apache.hadoop"),
"org.apache.parquet" % "parquet-avro" % "1.12.3" % "compile"
),
assembly / assemblyJarName := s"${name.value}-assembly_${scalaBinaryVersion.value}-${version.value}.jar",
assembly / logLevel := Level.Info,
assembly / test := {},
assembly / assemblyMergeStrategy := {
// Project hudi `dependsOn` spark and accidentally brings in it, along with its
// compile-time dependencies (like delta-storage). We want these excluded from the
// delta-hudi jar.
case PathList("io", "delta", xs @ _*) =>
// - delta-storage will bring in classes: io/delta/storage
// - delta-spark will bring in classes: io/delta/exceptions/, io/delta/implicits,
// io/delta/package, io/delta/sql, io/delta/tables,
MergeStrategy.discard
case PathList("com", "databricks", xs @ _*) =>
// delta-spark will bring in com/databricks/spark/util
MergeStrategy.discard
case PathList("org", "apache", "spark", "sql", "delta", "hudi", xs @ _*) =>
MergeStrategy.first
case PathList("org", "apache", "spark", xs @ _*) =>
MergeStrategy.discard
// Discard `module-info.class` to fix the `different file contents found` error.
// TODO Upgrade SBT to 1.5 which will do this automatically
case "module-info.class" => MergeStrategy.discard
// Discard unused `parquet.thrift` so that we don't conflict the file used by the user
case "parquet.thrift" => MergeStrategy.discard
// Hudi metadata writer requires this service file to be present on the classpath
case "META-INF/services/org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory" => MergeStrategy.first
// Discard the jackson service configs that we don't need. These files are not shaded so
// adding them may conflict with other jackson version used by the user.
case PathList("META-INF", "services", xs @ _*) => MergeStrategy.discard
case x =>
MergeStrategy.first
},
// Make the 'compile' invoke the 'assembly' task to generate the uber jar.
Compile / packageBin := assembly.value
)
lazy val hive = (project in file("connectors/hive"))
.dependsOn(standaloneCosmetic)
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "delta-hive",
commonSettings,
releaseSettings,
// Minimal dependencies to compile the codes. This project doesn't run any tests so we don't
// need any runtime dependencies.
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-client" % hadoopVersionForHive3 % "provided",
"org.apache.hive" % "hive-exec" % hiveVersion % "provided" classifier "core",
"org.apache.hive" % "hive-metastore" % hiveVersion % "provided"
),
)
lazy val hiveAssembly = (project in file("connectors/hive-assembly"))
.dependsOn(hive)
.disablePlugins(JavaFormatterPlugin)
.settings(
name := "delta-hive-assembly",
Compile / unmanagedJars += (hive / Compile / packageBin / packageBin).value,
commonSettings,
skipReleaseSettings,
assembly / logLevel := Level.Info,
assembly / assemblyJarName := s"${name.value}_${scalaBinaryVersion.value}-${version.value}.jar",
assembly / test := {},
assembly / assemblyMergeStrategy := {
// Discard `module-info.class` to fix the `different file contents found` error.
// TODO Upgrade SBT to 1.5 which will do this automatically
case "module-info.class" => MergeStrategy.discard
// Discard unused `parquet.thrift` so that we don't conflict the file used by the user
case "parquet.thrift" => MergeStrategy.discard
// Discard the jackson service configs that we don't need. These files are not shaded so
// adding them may conflict with other jackson version used by the user.
case PathList("META-INF", "services", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
},
// Make the 'compile' invoke the 'assembly' task to generate the uber jar.
Compile / packageBin := assembly.value
)
lazy val hiveTest = (project in file("connectors/hive-test"))
.dependsOn(goldenTables % "test")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "hive-test",
// Make the project use the assembly jar to ensure we are testing the assembly jar that users
// will use in real environment.
Compile / unmanagedJars += (hiveAssembly / Compile / packageBin / packageBin).value,
commonSettings,
skipReleaseSettings,
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-client" % hadoopVersionForHive3 % "provided",
"org.apache.hive" % "hive-exec" % hiveVersion % "provided" classifier "core" excludeAll(
ExclusionRule("org.pentaho", "pentaho-aggdesigner-algorithm"),
ExclusionRule(organization = "org.eclipse.jetty"),
ExclusionRule(organization = "com.google.protobuf")
),
"org.apache.hive" % "hive-metastore" % hiveVersion % "provided" excludeAll(
ExclusionRule(organization = "org.eclipse.jetty"),
ExclusionRule("org.apache.hive", "hive-exec")
),
"org.apache.hive" % "hive-cli" % hiveVersion % "test" excludeAll(
ExclusionRule("ch.qos.logback", "logback-classic"),
ExclusionRule("org.pentaho", "pentaho-aggdesigner-algorithm"),
ExclusionRule("org.apache.hive", "hive-exec"),
ExclusionRule("com.google.guava", "guava"),
ExclusionRule(organization = "org.eclipse.jetty"),
ExclusionRule(organization = "com.google.protobuf")
),
"org.scalatest" %% "scalatest" % scalaTestVersionForConnectors % "test"
)
)
lazy val hiveMR = (project in file("connectors/hive-mr"))
.dependsOn(hiveTest % "test->test")
.disablePlugins(JavaFormatterPlugin)
.settings (
name := "hive-mr",
commonSettings,
skipReleaseSettings,