-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize the implementation of spark writer (#51)
- Loading branch information
Showing
19 changed files
with
810 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
spark/src/main/java/com/alibaba/graphar/GeneralParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
spark/src/main/scala/com/alibaba/graphar/utils/FileSystem.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** Copyright 2022 Alibaba Group Holding Limited. | ||
* | ||
* 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 com.alibaba.graphar.utils | ||
|
||
import java.net.URI | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.DataFrame | ||
import org.apache.hadoop.fs | ||
|
||
object FileSystem { | ||
private def renameSparkGeneratedFiles(spark: SparkSession, filePrefix: String): Unit = { | ||
val sc = spark.sparkContext | ||
val file_system = fs.FileSystem.get(new URI(filePrefix), spark.sparkContext.hadoopConfiguration) | ||
val path_pattern = new fs.Path(filePrefix + "part*") | ||
val files = file_system.globStatus(path_pattern) | ||
for (i <- 0 until files.length) { | ||
val file_name = files(i).getPath.getName | ||
val new_file_name = "chunk" + i.toString | ||
file_system.rename(new fs.Path(filePrefix + file_name), new fs.Path(filePrefix + new_file_name)) | ||
} | ||
} | ||
|
||
def writeDataFrame(dataFrame: DataFrame, fileType: String, outputPrefix: String): Unit = { | ||
val spark = dataFrame.sparkSession | ||
spark.conf.set("mapreduce.fileoutputcommitter.marksuccessfuljobs", "false") | ||
spark.conf.set("parquet.enable.summary-metadata", "false") | ||
// spark.conf.set("spark.sql.parquet.compression.codec", "zstd") | ||
dataFrame.write.mode("overwrite").format(fileType).save(outputPrefix) | ||
renameSparkGeneratedFiles(spark, outputPrefix) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spark/src/main/scala/com/alibaba/graphar/utils/Patitioner.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** Copyright 2022 Alibaba Group Holding Limited. | ||
* | ||
* 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 com.alibaba.graphar.utils | ||
|
||
import org.apache.spark.sql.types._ | ||
import org.apache.spark.Partitioner | ||
|
||
|
||
class ChunkPartitioner(partitions: Int, chunk_size: Long) extends Partitioner { | ||
require(partitions >= 0, s"Number of partitions ($partitions) cannot be negative.") | ||
|
||
def numPartitions: Int = partitions | ||
|
||
def chunkSize: Long = chunk_size | ||
|
||
def getPartition(key: Any): Int = key match { | ||
case null => 0 | ||
case _ => (key.asInstanceOf[Long] / chunk_size).toInt | ||
} | ||
|
||
override def equals(other: Any): Boolean = other match { | ||
case h: ChunkPartitioner => | ||
h.numPartitions == numPartitions | ||
case _ => | ||
false | ||
} | ||
|
||
override def hashCode: Int = numPartitions | ||
} |
Oops, something went wrong.