|
| 1 | +--- |
1 | 2 | title: CallMethodViaReflection
|
| 3 | +--- |
2 | 4 |
|
3 | 5 | # CallMethodViaReflection Expression
|
4 | 6 |
|
5 |
| -`CallMethodViaReflection` is an Expression.md[expression] that represents a static method call in Scala or Java using `reflect` and `java_method` functions. |
| 7 | +`CallMethodViaReflection` is a [non-deterministic expression](Nondeterministic.md) that represents a static method call (in Scala or Java) using `reflect` and `java_method` standard functions. |
6 | 8 |
|
7 |
| -NOTE: `reflect` and `java_method` functions are only supported in SparkSession.md#sql[SQL] and dataset/index.md#selectExpr[expression] modes. |
| 9 | +`CallMethodViaReflection` supports [fallback mode for expression code generation](Expression.md#CodegenFallback). |
8 | 10 |
|
9 |
| -.CallMethodViaReflection's DataType to JVM Types Mapping |
10 |
| -[cols="1,2",options="header",width="100%"] |
11 |
| -|=== |
12 |
| -| DataType |
13 |
| -| JVM Type |
| 11 | +## Creating Instance |
14 | 12 |
|
15 |
| -| `BooleanType` |
16 |
| -| `java.lang.Boolean` / `scala.Boolean` |
| 13 | +`CallMethodViaReflection` takes the following to be created: |
17 | 14 |
|
18 |
| -| `ByteType` |
19 |
| -| `java.lang.Byte` / `Byte` |
| 15 | +* <span id="children"> Children [Expression](Expression.md)s |
20 | 16 |
|
21 |
| -| `ShortType` |
22 |
| -| `java.lang.Short` / `Short` |
| 17 | +`CallMethodViaReflection` is created when: |
23 | 18 |
|
24 |
| -| `IntegerType` |
25 |
| -| `java.lang.Integer` / `Int` |
| 19 | +* `reflect` standard function is used |
26 | 20 |
|
27 |
| -| `LongType` |
28 |
| -| `java.lang.Long` / `Long` |
| 21 | +## evalInternal { #evalInternal } |
29 | 22 |
|
30 |
| -| `FloatType` |
31 |
| -| `java.lang.Float` / `Float` |
| 23 | +??? note "Nondeterministic" |
32 | 24 |
|
33 |
| -| `DoubleType` |
34 |
| -| `java.lang.Double` / `Double` |
| 25 | + ```scala |
| 26 | + evalInternal( |
| 27 | + input: InternalRow): Any |
| 28 | + ``` |
35 | 29 |
|
36 |
| -| `StringType` |
37 |
| -| `String` |
38 |
| -|=== |
| 30 | + `evalInternal` is part of the [Nondeterministic](Nondeterministic.md#evalInternal) abstraction. |
39 | 31 |
|
40 |
| -[source, scala] |
41 |
| ----- |
| 32 | +`evalInternal`...FIXME |
| 33 | + |
| 34 | +## initializeInternal { #initializeInternal } |
| 35 | + |
| 36 | +??? note "Nondeterministic" |
| 37 | + |
| 38 | + ```scala |
| 39 | + initializeInternal( |
| 40 | + partitionIndex: Int): Unit |
| 41 | + ``` |
| 42 | + |
| 43 | + `initializeInternal` is part of the [Nondeterministic](Nondeterministic.md#initializeInternal) abstraction. |
| 44 | + |
| 45 | +`initializeInternal`...FIXME |
| 46 | + |
| 47 | +## Demo |
| 48 | + |
| 49 | +```scala |
42 | 50 | import org.apache.spark.sql.catalyst.expressions.CallMethodViaReflection
|
43 | 51 | import org.apache.spark.sql.catalyst.expressions.Literal
|
44 |
| -scala> val expr = CallMethodViaReflection( |
45 |
| - | Literal("java.time.LocalDateTime") :: |
46 |
| - | Literal("now") :: Nil) |
47 |
| -expr: org.apache.spark.sql.catalyst.expressions.CallMethodViaReflection = reflect(java.time.LocalDateTime, now) |
| 52 | +val expr = CallMethodViaReflection( |
| 53 | + Literal("java.time.LocalDateTime") :: |
| 54 | + Literal("now") :: Nil) |
| 55 | +``` |
| 56 | + |
| 57 | +```text |
48 | 58 | scala> println(expr.numberedTreeString)
|
49 |
| -00 reflect(java.time.LocalDateTime, now) |
| 59 | +00 reflect(java.time.LocalDateTime, now, true) |
50 | 60 | 01 :- java.time.LocalDateTime
|
51 | 61 | 02 +- now
|
| 62 | +``` |
52 | 63 |
|
53 |
| -// CallMethodViaReflection as the expression for reflect SQL function |
54 |
| -val q = """ |
55 |
| - select reflect("java.time.LocalDateTime", "now") as now |
56 |
| - """ |
| 64 | +```scala |
| 65 | +val q = """SELECT reflect("java.time.LocalDateTime", "now") AS now""" |
57 | 66 | val plan = spark.sql(q).queryExecution.logical
|
| 67 | +``` |
| 68 | + |
| 69 | +```text |
58 | 70 | // CallMethodViaReflection shows itself under "reflect" name
|
59 | 71 | scala> println(plan.numberedTreeString)
|
60 |
| -00 Project [reflect(java.time.LocalDateTime, now) AS now#39] |
61 |
| -01 +- OneRowRelation$ |
62 |
| ----- |
63 |
| - |
64 |
| -`CallMethodViaReflection` supports a Expression.md#CodegenFallback[fallback mode for expression code generation]. |
65 |
| - |
66 |
| -[[properties]] |
67 |
| -.CallMethodViaReflection's Properties |
68 |
| -[width="100%",cols="1,2",options="header"] |
69 |
| -|=== |
70 |
| -| Property |
71 |
| -| Description |
72 |
| - |
73 |
| -| [[dataType]] `dataType` |
74 |
| -| `StringType` |
75 |
| - |
76 |
| -| [[deterministic]] `deterministic` |
77 |
| -| Disabled (i.e. `false`) |
78 |
| - |
79 |
| -| [[nullable]] `nullable` |
80 |
| -| Enabled (i.e. `true`) |
81 |
| - |
82 |
| -| [[prettyName]] `prettyName` |
83 |
| -| `reflect` |
84 |
| -|=== |
85 |
| - |
86 |
| -NOTE: `CallMethodViaReflection` is very similar to spark-sql-Expression-StaticInvoke.md[StaticInvoke] expression. |
| 72 | +00 'Project ['reflect(java.time.LocalDateTime, now) AS now#0] |
| 73 | +01 +- OneRowRelation |
| 74 | +``` |
0 commit comments