forked from apache/datafusion-comet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCometExpressionSerde.scala
More file actions
90 lines (83 loc) · 3.3 KB
/
CometExpressionSerde.scala
File metadata and controls
90 lines (83 loc) · 3.3 KB
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
/*
* 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.comet.serde
import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
/**
* Trait for providing serialization logic for expressions.
*/
trait CometExpressionSerde[T <: Expression] {
/**
* Get a short name for the expression that can be used as part of a config key related to the
* expression, such as enabling or disabling that expression.
*
* @param expr
* The Spark expression.
* @return
* Short name for the expression, defaulting to the Spark class name
*/
def getExprConfigName(expr: T): String = expr.getClass.getSimpleName
/**
* Declarative support conditions for this expression. First match wins.
*
* Prefer declaring `conditions` over overriding [[getSupportLevel]]: the list is enumerable for
* documentation and tests, and each condition carries a stable id and static description.
*
* Subclasses should declare `conditions` as a `val` so the list is built once, not on every
* `getSupportLevel` call.
*/
def conditions: Seq[SupportCondition[T]] = Seq.empty
/**
* Determine the support level of the expression based on its attributes.
*
* The default implementation is derived from [[conditions]]. Subclasses may still override this
* during migration, but new serdes should prefer declaring `conditions`.
*
* @param expr
* The Spark expression.
* @return
* Support level (Compatible, Incompatible, or Unsupported).
*/
def getSupportLevel(expr: T): SupportLevel =
conditions.find(_.fires(expr)) match {
case Some(c) =>
val msg = Some(c.message(expr)).filter(_.nonEmpty)
c.level match {
case SupportLevelKind.Compatible => Compatible(msg)
case SupportLevelKind.Incompatible => Incompatible(msg)
case SupportLevelKind.Unsupported => Unsupported(msg)
}
case None => Compatible(None)
}
/**
* Convert a Spark expression into a protocol buffer representation that can be passed into
* native code.
*
* @param expr
* The Spark expression.
* @param inputs
* The input attributes.
* @param binding
* Whether the attributes are bound (this is only relevant in aggregate expressions).
* @return
* Protocol buffer representation, or None if the expression could not be converted. In this
* case it is expected that the input expression will have been tagged with reasons why it
* could not be converted.
*/
def convert(expr: T, inputs: Seq[Attribute], binding: Boolean): Option[ExprOuterClass.Expr]
}