-
Notifications
You must be signed in to change notification settings - Fork 29k
Spark-24742: Fix NullPointerexception in Field Metadata #21722
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… values
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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.spark.sql.types | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
|
|
||
| class MetadataSuite extends SparkFunSuite { | ||
| test("String Metadata") { | ||
|
||
| val meta = new MetadataBuilder().putString("key", "value").build() | ||
| assert(meta.## != 0) | ||
| assert(meta.getString("key") == "value") | ||
| assert(meta.contains("key")) | ||
| intercept[NoSuchElementException](meta.getString("no_such_key")) | ||
| intercept[ClassCastException](meta.getBoolean("key")) | ||
| } | ||
|
|
||
| test("Long Metadata") { | ||
| val meta = new MetadataBuilder().putLong("key", 12).build() | ||
| assert(meta.## != 0) | ||
| assert(meta.getLong("key") == 12) | ||
| assert(meta.contains("key")) | ||
| intercept[NoSuchElementException](meta.getLong("no_such_key")) | ||
| intercept[ClassCastException](meta.getBoolean("key")) | ||
| } | ||
|
|
||
| test("Double Metadata") { | ||
| val meta = new MetadataBuilder().putDouble("key", 12).build() | ||
| assert(meta.## != 0) | ||
| assert(meta.getDouble("key") == 12) | ||
| assert(meta.contains("key")) | ||
| intercept[NoSuchElementException](meta.getDouble("no_such_key")) | ||
| intercept[ClassCastException](meta.getBoolean("key")) | ||
| } | ||
|
|
||
| test("Boolean Metadata") { | ||
| val meta = new MetadataBuilder().putBoolean("key", true).build() | ||
| assert(meta.## != 0) | ||
| assert(meta.getBoolean("key") == true) | ||
| assert(meta.contains("key")) | ||
| intercept[NoSuchElementException](meta.getBoolean("no_such_key")) | ||
| intercept[ClassCastException](meta.getString("key")) | ||
| } | ||
|
|
||
| test("Null Metadata") { | ||
| val meta = new MetadataBuilder().putNull("key").build() | ||
| assert(meta.## != 0) | ||
| assert(meta.getString("key") == null) | ||
| assert(meta.getDouble("key") == 0) | ||
| assert(meta.getLong("key") == 0) | ||
| assert(meta.getBoolean("key") == false) | ||
| assert(meta.contains("key")) | ||
| intercept[NoSuchElementException](meta.getLong("no_such_key")) | ||
| } | ||
| } | ||
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.
Basically, we do not support
nullin Metadata.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.
nvm, I found we added the support in #8969
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.
Yes, the
putNullmethod exists, but is actually not useable because of this bug. Havingnullin Metadata would be really helpful for me, as I'd like to store default values for fields in the Metadata. And NULL is a very common case as a default value.