-
Notifications
You must be signed in to change notification settings - Fork 461
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
1 parent
5755368
commit 6a042ba
Showing
23 changed files
with
588 additions
and
94 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
110 changes: 110 additions & 0 deletions
110
backends-clickhouse/src/main/scala/org/apache/gluten/execution/CHRangeExecTransformer.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,110 @@ | ||
/* | ||
* 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.gluten.execution | ||
|
||
import org.apache.gluten.backendsapi.BackendsApiManager | ||
import org.apache.gluten.expression.ConverterUtils | ||
import org.apache.gluten.extension.ValidationResult | ||
import org.apache.gluten.metrics.{CHRangeMetricsUpdater, MetricsUpdater} | ||
import org.apache.gluten.substrait.`type`._ | ||
import org.apache.gluten.substrait.SubstraitContext | ||
import org.apache.gluten.substrait.extensions.ExtensionBuilder | ||
import org.apache.gluten.substrait.rel.{RelBuilder, SplitInfo} | ||
|
||
import org.apache.spark.sql.catalyst.expressions.Attribute | ||
import org.apache.spark.sql.connector.read.InputPartition | ||
import org.apache.spark.sql.execution.datasources.clickhouse.ExtensionTableBuilder | ||
import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics} | ||
|
||
import com.google.protobuf.StringValue | ||
import io.substrait.proto.NamedStruct | ||
|
||
import scala.collection.JavaConverters; | ||
|
||
case class CHRangeExecTransformer(range: org.apache.spark.sql.catalyst.plans.logical.Range) | ||
extends LeafTransformSupport { | ||
|
||
override def output: Seq[Attribute] = range.output | ||
|
||
override def getSplitInfos: Seq[SplitInfo] = { | ||
val start = range.start | ||
val end = range.end | ||
val step = range.step | ||
val numSlices = range.numSlices.getOrElse(1) | ||
|
||
(0 until numSlices).map { | ||
sliceIndex => | ||
ExtensionTableBuilder.makeExtensionTable(start, end, step, numSlices, sliceIndex) | ||
} | ||
} | ||
|
||
override def getPartitions: Seq[InputPartition] = { | ||
val start = range.start | ||
val end = range.end | ||
val step = range.step | ||
val numSlices = range.numSlices.getOrElse(1) | ||
|
||
(0 until numSlices).map { | ||
sliceIndex => GlutenRangeExecPartition(start, end, step, numSlices, sliceIndex) | ||
} | ||
} | ||
|
||
@transient | ||
override lazy val metrics: Map[String, SQLMetric] = | ||
Map( | ||
"numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number of output rows"), | ||
"outputVectors" -> SQLMetrics.createMetric(sparkContext, "number of output vectors"), | ||
"outputBytes" -> SQLMetrics.createSizeMetric(sparkContext, "number of output bytes"), | ||
"numInputRows" -> SQLMetrics.createMetric(sparkContext, "number of input rows"), | ||
"inputBytes" -> SQLMetrics.createSizeMetric(sparkContext, "number of input bytes"), | ||
"extraTime" -> SQLMetrics.createTimingMetric(sparkContext, "extra operators time"), | ||
"inputWaitTime" -> SQLMetrics.createTimingMetric(sparkContext, "time of waiting for data"), | ||
"outputWaitTime" -> SQLMetrics.createTimingMetric(sparkContext, "time of waiting for output"), | ||
"totalTime" -> SQLMetrics.createTimingMetric(sparkContext, "time") | ||
) | ||
|
||
override def metricsUpdater(): MetricsUpdater = new CHRangeMetricsUpdater(metrics) | ||
|
||
// No need to do native validation for CH backend. It is validated in [[doTransform]]. | ||
override protected def doValidateInternal(): ValidationResult = ValidationResult.succeeded | ||
|
||
override def doTransform(context: SubstraitContext): TransformContext = { | ||
val output = range.output | ||
val typeNodes = ConverterUtils.collectAttributeTypeNodes(output) | ||
val nameList = ConverterUtils.collectAttributeNamesWithoutExprId(output) | ||
val columnTypeNodes = JavaConverters | ||
.seqAsJavaListConverter( | ||
output.map(attr => new ColumnTypeNode(NamedStruct.ColumnType.NORMAL_COL))) | ||
.asJava | ||
|
||
val optimizationContent = s"isRange=1\n" | ||
val optimization = | ||
BackendsApiManager.getTransformerApiInstance.packPBMessage( | ||
StringValue.newBuilder.setValue(optimizationContent).build) | ||
val extensionNode = ExtensionBuilder.makeAdvancedExtension(optimization, null) | ||
val readNode = RelBuilder.makeReadRel( | ||
typeNodes, | ||
nameList, | ||
columnTypeNodes, | ||
null, | ||
extensionNode, | ||
context, | ||
context.nextOperatorId(this.nodeName)) | ||
|
||
TransformContext(output, readNode) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ends-clickhouse/src/main/scala/org/apache/gluten/execution/GlutenRangeExecPartition.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,28 @@ | ||
/* | ||
* 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.gluten.execution | ||
|
||
import org.apache.gluten.substrait.plan.PlanBuilder | ||
|
||
case class GlutenRangeExecPartition( | ||
start: Long, | ||
end: Long, | ||
step: Long, | ||
numSlices: Int, | ||
index: Int, | ||
plan: Array[Byte] = PlanBuilder.EMPTY_PLAN) | ||
extends BaseGlutenPartition {} |
51 changes: 51 additions & 0 deletions
51
backends-clickhouse/src/main/scala/org/apache/gluten/metrics/CHRangeMetricsUpdater.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,51 @@ | ||
/* | ||
* 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.gluten.metrics | ||
|
||
import org.apache.spark.sql.execution.metric.SQLMetric | ||
|
||
class CHRangeMetricsUpdater(val metrics: Map[String, SQLMetric]) extends MetricsUpdater { | ||
override def updateNativeMetrics(opMetrics: IOperatorMetrics): Unit = { | ||
if (opMetrics != null) { | ||
val operatorMetrics = opMetrics.asInstanceOf[OperatorMetrics] | ||
if (!operatorMetrics.metricsList.isEmpty) { | ||
val metricsData = operatorMetrics.metricsList.get(0) | ||
metrics("totalTime") += (metricsData.time / 1000L).toLong | ||
metrics("inputWaitTime") += (metricsData.inputWaitTime / 1000L).toLong | ||
metrics("outputWaitTime") += (metricsData.outputWaitTime / 1000L).toLong | ||
metrics("outputVectors") += metricsData.outputVectors | ||
|
||
MetricsUtil.updateExtraTimeMetric( | ||
metricsData, | ||
metrics("extraTime"), | ||
metrics("numOutputRows"), | ||
metrics("outputBytes"), | ||
metrics("numInputRows"), | ||
metrics("inputBytes"), | ||
GenerateMetricsUpdater.INCLUDING_PROCESSORS, | ||
GenerateMetricsUpdater.CH_PLAN_NODE_NAME | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
object CHRangeMetricsUpdater { | ||
val INCLUDING_PROCESSORS: Array[String] = Array("SourceFromRange") | ||
val CH_PLAN_NODE_NAME: Array[String] = Array("SourceFromRange") | ||
} |
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.