-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-20536][SQL] Extend ColumnName to create StructFields with explicit nullable #20832
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1208,85 +1208,172 @@ class ColumnName(name: String) extends Column(name) { | |
*/ | ||
def boolean: StructField = StructField(name, BooleanType) | ||
|
||
/** | ||
* Creates a new `StructField` of type boolean. | ||
* @since 2.3.0 | ||
*/ | ||
def boolean(nullable: Boolean): StructField = StructField(name, BooleanType, nullable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The NULL hints are not enforced. Thus, it is kind of risky to expose this to end users since it could generate a wrong result. We plan to ignore the user-specified NULL hints in the upcoming release. |
||
|
||
/** | ||
* Creates a new `StructField` of type byte. | ||
* @since 1.3.0 | ||
*/ | ||
def byte: StructField = StructField(name, ByteType) | ||
|
||
/** | ||
* Creates a new `StructField` of type byte. | ||
* @since 2.3.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
def byte(nullable: Boolean): StructField = StructField(name, ByteType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type short. | ||
* @since 1.3.0 | ||
*/ | ||
def short: StructField = StructField(name, ShortType) | ||
|
||
/** | ||
* Creates a new `StructField` of type short. | ||
* @since 2.3.0 | ||
*/ | ||
def short(nullable: Boolean): StructField = StructField(name, ShortType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type int. | ||
* @since 1.3.0 | ||
*/ | ||
def int: StructField = StructField(name, IntegerType) | ||
|
||
/** | ||
* Creates a new `StructField` of type int. | ||
* @since 2.3.0 | ||
*/ | ||
def int(nullable: Boolean): StructField = StructField(name, IntegerType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type long. | ||
* @since 1.3.0 | ||
*/ | ||
def long: StructField = StructField(name, LongType) | ||
|
||
/** | ||
* Creates a new `StructField` of type long. | ||
* @since 2.3.0 | ||
*/ | ||
def long(nullable: Boolean): StructField = StructField(name, LongType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type float. | ||
* @since 1.3.0 | ||
*/ | ||
def float: StructField = StructField(name, FloatType) | ||
|
||
/** | ||
* Creates a new `StructField` of type float. | ||
* @since 2.3.0 | ||
*/ | ||
def float(nullable: Boolean): StructField = StructField(name, FloatType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type double. | ||
* @since 1.3.0 | ||
*/ | ||
def double: StructField = StructField(name, DoubleType) | ||
|
||
/** | ||
* Creates a new `StructField` of type double. | ||
* @since 2.3.0 | ||
*/ | ||
def double(nullable: Boolean): StructField = StructField(name, DoubleType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type string. | ||
* @since 1.3.0 | ||
*/ | ||
def string: StructField = StructField(name, StringType) | ||
|
||
/** | ||
* Creates a new `StructField` of type string. | ||
* @since 2.3.0 | ||
*/ | ||
def string(nullable: Boolean): StructField = StructField(name, StringType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type date. | ||
* @since 1.3.0 | ||
*/ | ||
def date: StructField = StructField(name, DateType) | ||
|
||
/** | ||
* Creates a new `StructField` of type date. | ||
* @since 2.3.0 | ||
*/ | ||
def date(nullable: Boolean): StructField = StructField(name, DateType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type decimal. | ||
* @since 1.3.0 | ||
*/ | ||
def decimal: StructField = StructField(name, DecimalType.USER_DEFAULT) | ||
|
||
/** | ||
* Creates a new `StructField` of type decimal. | ||
* @since 2.3.0 | ||
*/ | ||
def decimal(nullable: Boolean): StructField = | ||
StructField(name, DecimalType.USER_DEFAULT, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type decimal. | ||
* @since 1.3.0 | ||
*/ | ||
def decimal(precision: Int, scale: Int): StructField = | ||
StructField(name, DecimalType(precision, scale)) | ||
|
||
/** | ||
* Creates a new `StructField` of type decimal. | ||
* @since 2.3.0 | ||
*/ | ||
def decimal(precision: Int, scale: Int, nullable: Boolean): StructField = | ||
StructField(name, DecimalType(precision, scale), nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type timestamp. | ||
* @since 1.3.0 | ||
*/ | ||
def timestamp: StructField = StructField(name, TimestampType) | ||
|
||
/** | ||
* Creates a new `StructField` of type timestamp. | ||
* @since 2.3.0 | ||
*/ | ||
def timestamp(nullable: Boolean): StructField = StructField(name, TimestampType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type binary. | ||
* @since 1.3.0 | ||
*/ | ||
def binary: StructField = StructField(name, BinaryType) | ||
|
||
/** | ||
* Creates a new `StructField` of type binary. | ||
* @since 2.3.0 | ||
*/ | ||
def binary(nullable: Boolean): StructField = StructField(name, BinaryType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type array. | ||
* @since 1.3.0 | ||
*/ | ||
def array(dataType: DataType): StructField = StructField(name, ArrayType(dataType)) | ||
|
||
/** | ||
* Creates a new `StructField` of type array. | ||
* @since 2.3.0 | ||
*/ | ||
def array(dataType: DataType, nullable: Boolean): StructField = | ||
StructField(name, ArrayType(dataType), nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type map. | ||
* @since 1.3.0 | ||
|
@@ -1296,6 +1383,12 @@ class ColumnName(name: String) extends Column(name) { | |
|
||
def map(mapType: MapType): StructField = StructField(name, mapType) | ||
|
||
/** | ||
* Creates a new `StructField` of type map. | ||
* @since 2.3.0 | ||
*/ | ||
def map(mapType: MapType, nullable: Boolean): StructField = StructField(name, mapType, nullable) | ||
|
||
/** | ||
* Creates a new `StructField` of type struct. | ||
* @since 1.3.0 | ||
|
@@ -1307,4 +1400,11 @@ class ColumnName(name: String) extends Column(name) { | |
* @since 1.3.0 | ||
*/ | ||
def struct(structType: StructType): StructField = StructField(name, structType) | ||
|
||
/** | ||
* Creates a new `StructField` of type struct. | ||
* @since 2.3.0 | ||
*/ | ||
def struct(structType: StructType, nullable: Boolean): StructField = | ||
StructField(name, structType, nullable) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.4.0
I thinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done