-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
290 additions
and
162 deletions.
There are no files selected for viewing
72 changes: 0 additions & 72 deletions
72
.../paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
This file was deleted.
Oops, something went wrong.
84 changes: 0 additions & 84 deletions
84
...n-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkReaderFactory.java
This file was deleted.
Oops, something went wrong.
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
124 changes: 124 additions & 0 deletions
124
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonMetrics.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,124 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.paimon.spark | ||
|
||
import org.apache.spark.sql.Utils | ||
import org.apache.spark.sql.connector.metric.{CustomAvgMetric, CustomSumMetric, CustomTaskMetric} | ||
|
||
import java.text.DecimalFormat | ||
|
||
object PaimonMetrics { | ||
|
||
val NUM_SPLITS = "numSplits" | ||
|
||
val SPLIT_SIZE = "splitSize" | ||
|
||
val AVG_SPLIT_SIZE = "avgSplitSize" | ||
} | ||
|
||
// paimon's task metric | ||
sealed trait PaimonTaskMetric extends CustomTaskMetric | ||
|
||
case class PaimonNumSplitsTaskMetric(override val value: Long) extends PaimonTaskMetric { | ||
|
||
override def name(): String = PaimonMetrics.NUM_SPLITS | ||
|
||
} | ||
|
||
case class PaimonSplitSizeTaskMetric(override val value: Long) extends PaimonTaskMetric { | ||
|
||
override def name(): String = PaimonMetrics.SPLIT_SIZE | ||
|
||
} | ||
|
||
case class PaimonAvgSplitSizeTaskMetric(override val value: Long) extends PaimonTaskMetric { | ||
|
||
override def name(): String = PaimonMetrics.AVG_SPLIT_SIZE | ||
|
||
} | ||
|
||
// paimon's sum metric | ||
sealed trait PaimonSumMetric extends CustomSumMetric { | ||
|
||
protected def aggregateTaskMetrics0(taskMetrics: Array[Long]): Long = { | ||
var sum: Long = 0L | ||
for (taskMetric <- taskMetrics) { | ||
sum += taskMetric | ||
} | ||
sum | ||
} | ||
|
||
override def aggregateTaskMetrics(taskMetrics: Array[Long]): String = { | ||
String.valueOf(aggregateTaskMetrics0(taskMetrics)) | ||
} | ||
|
||
} | ||
|
||
case class PaimonNumSplitMetric() extends PaimonSumMetric { | ||
|
||
override def name(): String = PaimonMetrics.NUM_SPLITS | ||
|
||
override def description(): String = "number of splits read" | ||
|
||
} | ||
|
||
case class PaimonSplitSizeMetric() extends PaimonSumMetric { | ||
|
||
override def name(): String = PaimonMetrics.SPLIT_SIZE | ||
|
||
override def description(): String = "size of splits read" | ||
|
||
override def aggregateTaskMetrics(taskMetrics: Array[Long]): String = { | ||
Utils.bytesToString(aggregateTaskMetrics0(taskMetrics)) | ||
} | ||
} | ||
|
||
// paimon's avg metric | ||
sealed trait PaimonAvgMetric extends CustomAvgMetric { | ||
|
||
protected def aggregateTaskMetrics0(taskMetrics: Array[Long]): Double = { | ||
if (taskMetrics.length > 0) { | ||
var sum = 0L | ||
for (taskMetric <- taskMetrics) { | ||
sum += taskMetric | ||
} | ||
sum.toDouble / taskMetrics.length | ||
} else { | ||
0d | ||
} | ||
} | ||
|
||
override def aggregateTaskMetrics(taskMetrics: Array[Long]): String = { | ||
val average = aggregateTaskMetrics0(taskMetrics) | ||
new DecimalFormat("#0.000").format(average) | ||
} | ||
|
||
} | ||
|
||
case class PaimonAvgSplitSizeMetric() extends PaimonAvgMetric { | ||
|
||
override def name(): String = PaimonMetrics.AVG_SPLIT_SIZE | ||
|
||
override def description(): String = "avg size of splits read" | ||
|
||
override def aggregateTaskMetrics(taskMetrics: Array[Long]): String = { | ||
val average = aggregateTaskMetrics0(taskMetrics).round | ||
Utils.bytesToString(average) | ||
} | ||
|
||
} |
Oops, something went wrong.