forked from GoogleCloudDataproc/spark-bigquery-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
publish metrics using spark custom metrics API (GoogleCloudDataproc#1008
) * WIP * adding custom metrics into new module * addressing review comments * updating readme-template and changes.md
- Loading branch information
Showing
29 changed files
with
548 additions
and
12 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
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
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
46 changes: 46 additions & 0 deletions
46
...-lib/src/main/java/com/google/cloud/spark/bigquery/v2/Spark32BigQueryPartitionReader.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.google.cloud.spark.bigquery.v2; | ||
|
||
import static com.google.cloud.spark.bigquery.v2.customMetrics.SparkBigQueryCustomMetricConstants.*; | ||
|
||
import com.google.cloud.spark.bigquery.v2.context.InputPartitionReaderContext; | ||
import com.google.cloud.spark.bigquery.v2.customMetrics.SparkBigQueryTaskMetric; | ||
import org.apache.spark.sql.connector.metric.CustomTaskMetric; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Spark32BigQueryPartitionReader<T> extends BigQueryPartitionReader { | ||
|
||
public Logger log = LoggerFactory.getLogger(this.getClass()); | ||
private InputPartitionReaderContext<T> context; | ||
|
||
public Spark32BigQueryPartitionReader(InputPartitionReaderContext context) { | ||
super(context); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public CustomTaskMetric[] currentMetricsValues() { | ||
log.trace("in current metric values"); | ||
return context | ||
.getBigQueryStorageReadRowsTracer() | ||
.map( | ||
bigQueryStorageReadRowsTracer -> | ||
new SparkBigQueryTaskMetric[] { | ||
new SparkBigQueryTaskMetric( | ||
BIG_QUERY_BYTES_READ_METRIC_NAME, | ||
bigQueryStorageReadRowsTracer.getBytesRead()), | ||
new SparkBigQueryTaskMetric( | ||
BIG_QUERY_ROWS_READ_METRIC_NAME, bigQueryStorageReadRowsTracer.getRowsRead()), | ||
new SparkBigQueryTaskMetric( | ||
BIG_QUERY_SCAN_TIME_METRIC_NAME, | ||
bigQueryStorageReadRowsTracer.getScanTimeInMilliSec()), | ||
new SparkBigQueryTaskMetric( | ||
BIG_QUERY_PARSE_TIME_METRIC_NAME, | ||
bigQueryStorageReadRowsTracer.getParseTimeInMilliSec()), | ||
new SparkBigQueryTaskMetric( | ||
BIG_QUERY_TIME_IN_SPARK_METRIC_NAME, | ||
bigQueryStorageReadRowsTracer.getTimeInSparkInMilliSec()) | ||
}) | ||
.orElse(new SparkBigQueryTaskMetric[] {}); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...c/main/java/com/google/cloud/spark/bigquery/v2/Spark32BigQueryPartitionReaderFactory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.google.cloud.spark.bigquery.v2; | ||
|
||
import com.google.cloud.spark.bigquery.v2.context.InputPartitionContext; | ||
import org.apache.spark.sql.catalyst.InternalRow; | ||
import org.apache.spark.sql.connector.read.InputPartition; | ||
import org.apache.spark.sql.connector.read.PartitionReader; | ||
import org.apache.spark.sql.connector.read.PartitionReaderFactory; | ||
import org.apache.spark.sql.vectorized.ColumnarBatch; | ||
|
||
public class Spark32BigQueryPartitionReaderFactory implements PartitionReaderFactory { | ||
|
||
@Override | ||
public PartitionReader<InternalRow> createReader(InputPartition partition) { | ||
InputPartitionContext<InternalRow> ctx = ((BigQueryInputPartition) partition).getContext(); | ||
return new Spark32BigQueryPartitionReader<>(ctx.createPartitionReaderContext()); | ||
} | ||
|
||
@Override | ||
public PartitionReader<ColumnarBatch> createColumnarReader(InputPartition partition) { | ||
InputPartitionContext<ColumnarBatch> ctx = ((BigQueryInputPartition) partition).getContext(); | ||
return new Spark32BigQueryPartitionReader<>(ctx.createPartitionReaderContext()); | ||
} | ||
|
||
@Override | ||
public boolean supportColumnarReads(InputPartition partition) { | ||
InputPartitionContext ctx = ((BigQueryInputPartition) partition).getContext(); | ||
return ctx.supportColumnarReads(); | ||
} | ||
} |
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
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
Oops, something went wrong.