-
Notifications
You must be signed in to change notification settings - Fork 40
[PECOBLR-839] Fixed getString for boolean column #977
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
Merged
msrathore-db
merged 4 commits into
databricks:main
from
msrathore-db:PECOBLR-839-Fix-getString
Sep 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/test/java/com/databricks/jdbc/api/impl/converters/BitConverterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package com.databricks.jdbc.api.impl.converters; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import com.databricks.jdbc.exception.DatabricksSQLException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class BitConverterTest { | ||
|
|
||
| private final BitConverter bitConverter = new BitConverter(); | ||
|
|
||
| @Test | ||
| public void testToStringWithBooleanTrue() throws DatabricksSQLException { | ||
| assertEquals("true", bitConverter.toString(true)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToStringWithBooleanFalse() throws DatabricksSQLException { | ||
| assertEquals("false", bitConverter.toString(false)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToStringWithBooleanObject() throws DatabricksSQLException { | ||
| Boolean trueObject = Boolean.TRUE; | ||
| Boolean falseObject = Boolean.FALSE; | ||
|
|
||
| assertEquals("true", bitConverter.toString(trueObject)); | ||
| assertEquals("false", bitConverter.toString(falseObject)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToStringWithUnsupportedType() { | ||
| DatabricksSQLException exception = | ||
| assertThrows(DatabricksSQLException.class, () -> bitConverter.toString("not a boolean")); | ||
|
|
||
| assertTrue(exception.getMessage().contains("Unsupported String conversion operation")); | ||
| assertEquals("UNSUPPORTED_OPERATION", exception.getSQLState()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToStringWithNumber() { | ||
| DatabricksSQLException exception = | ||
| assertThrows(DatabricksSQLException.class, () -> bitConverter.toString(123)); | ||
|
|
||
| assertTrue(exception.getMessage().contains("Unsupported String conversion operation")); | ||
| assertEquals("UNSUPPORTED_OPERATION", exception.getSQLState()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithBooleanTrue() throws DatabricksSQLException { | ||
| assertTrue(bitConverter.toBoolean(true)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithBooleanFalse() throws DatabricksSQLException { | ||
| assertFalse(bitConverter.toBoolean(false)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithBooleanObject() throws DatabricksSQLException { | ||
| Boolean trueObject = Boolean.TRUE; | ||
| Boolean falseObject = Boolean.FALSE; | ||
|
|
||
| assertTrue(bitConverter.toBoolean(trueObject)); | ||
| assertFalse(bitConverter.toBoolean(falseObject)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithNumberZero() throws DatabricksSQLException { | ||
| assertFalse(bitConverter.toBoolean(0)); | ||
| assertFalse(bitConverter.toBoolean(0L)); | ||
| assertFalse(bitConverter.toBoolean(0.0f)); | ||
| assertFalse(bitConverter.toBoolean(0.0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithNumberNonZero() throws DatabricksSQLException { | ||
| assertTrue(bitConverter.toBoolean(1)); | ||
| assertTrue(bitConverter.toBoolean(-1)); | ||
| assertTrue(bitConverter.toBoolean(42L)); | ||
| assertTrue(bitConverter.toBoolean(3.14f)); | ||
| assertTrue(bitConverter.toBoolean(2.71)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithStringTrue() throws DatabricksSQLException { | ||
| assertTrue(bitConverter.toBoolean("true")); | ||
| assertTrue(bitConverter.toBoolean("TRUE")); | ||
| assertTrue(bitConverter.toBoolean("True")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithStringFalse() throws DatabricksSQLException { | ||
| assertFalse(bitConverter.toBoolean("false")); | ||
| assertFalse(bitConverter.toBoolean("FALSE")); | ||
| assertFalse(bitConverter.toBoolean("False")); | ||
| assertFalse(bitConverter.toBoolean("anything else")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithUnsupportedType() { | ||
|
msrathore-db marked this conversation as resolved.
Outdated
|
||
| DatabricksSQLException exception = | ||
| assertThrows(DatabricksSQLException.class, () -> bitConverter.toBoolean(new Object())); | ||
|
|
||
| assertTrue(exception.getMessage().contains("Unsupported type for conversion to BIT")); | ||
| assertTrue(exception.getMessage().contains("Object")); | ||
| assertEquals("UNSUPPORTED_OPERATION", exception.getSQLState()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToBooleanWithNull() { | ||
| DatabricksSQLException exception = | ||
| assertThrows(DatabricksSQLException.class, () -> bitConverter.toBoolean(null)); | ||
|
|
||
| assertTrue(exception.getMessage().contains("Unsupported type for conversion to BIT")); | ||
| assertTrue(exception.getMessage().contains("null")); | ||
| assertEquals("UNSUPPORTED_OPERATION", exception.getSQLState()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.