Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/17848#discussion_r128444945
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
@@ -3185,170 +3185,207 @@ object functions {
val inputTypes = (1 to x).foldRight("Nil")((i, s) =>
{s"ScalaReflection.schemaFor(typeTag[A$i]).dataType :: $s"})
println(s"""
/**
- * Defines a user-defined function of ${x} arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of ${x} arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[$typeTags](f: Function$x[$types]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try($inputTypes).toOption
- UserDefinedFunction(f, dataType,
inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}""")
}
*/
/**
- * Defines a user-defined function of 0 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 0 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag](f: Function0[RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 1 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 1 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag](f: Function1[A1, RT]):
UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 2 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 2 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag](f: Function2[A1, A2,
RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 3 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 3 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag](f:
Function3[A1, A2, A3, RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 4 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 4 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4:
TypeTag](f: Function4[A1, A2, A3, A4, RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 5 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 5 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag,
A5: TypeTag](f: Function5[A1, A2, A3, A4, A5, RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType ::
ScalaReflection.schemaFor(typeTag[A5]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 6 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 6 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag,
A5: TypeTag, A6: TypeTag](f: Function6[A1, A2, A3, A4, A5, A6, RT]):
UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType ::
ScalaReflection.schemaFor(typeTag[A5]).dataType ::
ScalaReflection.schemaFor(typeTag[A6]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 7 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 7 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag,
A5: TypeTag, A6: TypeTag, A7: TypeTag](f: Function7[A1, A2, A3, A4, A5, A6, A7,
RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType ::
ScalaReflection.schemaFor(typeTag[A5]).dataType ::
ScalaReflection.schemaFor(typeTag[A6]).dataType ::
ScalaReflection.schemaFor(typeTag[A7]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 8 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 8 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag,
A5: TypeTag, A6: TypeTag, A7: TypeTag, A8: TypeTag](f: Function8[A1, A2, A3,
A4, A5, A6, A7, A8, RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType ::
ScalaReflection.schemaFor(typeTag[A5]).dataType ::
ScalaReflection.schemaFor(typeTag[A6]).dataType ::
ScalaReflection.schemaFor(typeTag[A7]).dataType ::
ScalaReflection.schemaFor(typeTag[A8]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 9 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 9 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag,
A5: TypeTag, A6: TypeTag, A7: TypeTag, A8: TypeTag, A9: TypeTag](f:
Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, RT]): UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType ::
ScalaReflection.schemaFor(typeTag[A5]).dataType ::
ScalaReflection.schemaFor(typeTag[A6]).dataType ::
ScalaReflection.schemaFor(typeTag[A7]).dataType ::
ScalaReflection.schemaFor(typeTag[A8]).dataType ::
ScalaReflection.schemaFor(typeTag[A9]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
/**
- * Defines a user-defined function of 10 arguments as user-defined
function (UDF).
- * The data types are automatically inferred based on the function's
signature.
+ * Defines a deterministic user-defined function of 10 arguments as
user-defined
+ * function (UDF). The data types are automatically inferred based on
the function's
+ * signature. To change a UDF to nondeterministic, call the API
+ * `UserDefinedFunction.asNondeterministic()`.
*
* @group udf_funcs
* @since 1.3.0
*/
def udf[RT: TypeTag, A1: TypeTag, A2: TypeTag, A3: TypeTag, A4: TypeTag,
A5: TypeTag, A6: TypeTag, A7: TypeTag, A8: TypeTag, A9: TypeTag, A10:
TypeTag](f: Function10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, RT]):
UserDefinedFunction = {
val ScalaReflection.Schema(dataType, nullable) =
ScalaReflection.schemaFor[RT]
val inputTypes = Try(ScalaReflection.schemaFor(typeTag[A1]).dataType
:: ScalaReflection.schemaFor(typeTag[A2]).dataType ::
ScalaReflection.schemaFor(typeTag[A3]).dataType ::
ScalaReflection.schemaFor(typeTag[A4]).dataType ::
ScalaReflection.schemaFor(typeTag[A5]).dataType ::
ScalaReflection.schemaFor(typeTag[A6]).dataType ::
ScalaReflection.schemaFor(typeTag[A7]).dataType ::
ScalaReflection.schemaFor(typeTag[A8]).dataType ::
ScalaReflection.schemaFor(typeTag[A9]).dataType ::
ScalaReflection.schemaFor(typeTag[A10]).dataType :: Nil).toOption
- UserDefinedFunction(f, dataType, inputTypes).withNullability(nullable)
+ val udf = UserDefinedFunction(f, dataType, inputTypes)
+ if (nullable) udf else udf.asNonNullabe()
}
// scalastyle:on parameter.number
// scalastyle:on line.size.limit
/**
- * Defines a user-defined function (UDF) using a Scala closure. For this
variant, the caller must
- * specify the output data type, and there is no automatic input type
coercion.
+ * Defines a deterministic user-defined function (UDF) using a Scala
closure. For this variant,
--- End diff --
not only scala closure, I think java UDF class is also supported here.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]