-
Notifications
You must be signed in to change notification settings - Fork 82
Added support for BIGINT UNSIGNED type in MySQL and MariaDB DBTypes
#1735
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
base: master
Are you sure you want to change the base?
Changes from all commits
fb75764
c3742a9
16e112e
8a0c1f8
4072587
8867e07
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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| @file:Suppress("ClassName") | ||
|
|
||
| package org.jetbrains.kotlinx.dataframe.io.db | ||
|
|
||
| import io.kotest.matchers.shouldBe | ||
| import org.junit.Test | ||
| import org.junit.experimental.runners.Enclosed | ||
| import org.junit.runner.RunWith | ||
| import java.math.BigInteger | ||
| import kotlin.reflect.KType | ||
| import kotlin.reflect.typeOf | ||
|
|
||
| // TODO: complete and enhance (#1736) | ||
| @RunWith(Enclosed::class) | ||
| class JdbcTypesTest { | ||
|
|
||
| abstract class ColumnType( | ||
| val sqlTypeName: String, | ||
| val jdbcType: Int, | ||
| val javaClassName: String, | ||
| val expectedKotlinType: KType, | ||
| ) { | ||
| fun mockkColMetaData() = | ||
| TableColumnMetadata( | ||
| "name", | ||
| sqlTypeName, | ||
| jdbcType, | ||
| 10, | ||
| javaClassName, | ||
| false, | ||
|
Collaborator
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. hmm by setting this to false always, you might not catch the cases where someone forgets to take care about nullability (which is an easy mistake to make). Maybe we should test both isNullable and !isNullable. This could also be done in a next pr of course |
||
| ) | ||
| } | ||
|
|
||
| class MariaDBTypes { | ||
|
|
||
| object BIGINT_UNSIGNED : ColumnType( | ||
| "BIGINT UNSIGNED", | ||
|
Collaborator
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. I'd recommend using named arguments. Makes refactoring easier :) |
||
| 20, | ||
| "java.math.BigInteger", | ||
| typeOf<BigInteger>(), | ||
| ) | ||
|
|
||
| val types: List<ColumnType> = listOf( | ||
| BIGINT_UNSIGNED, | ||
| ) | ||
|
|
||
| @Test | ||
| fun `all MariaDB SQL types should match expected type`() { | ||
| types.forEach { type -> | ||
| MariaDb.getExpectedJdbcType(type.mockkColMetaData()) shouldBe type.expectedKotlinType | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class MySqlDBTypes { | ||
|
|
||
| object BIGINT_UNSIGNED : ColumnType( | ||
| "BIGINT UNSIGNED", | ||
| 20, | ||
|
Collaborator
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. I'd use Sql.Types for this
Collaborator
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. oh, it doesn't exist?... interesting
Collaborator
Author
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. Yep, it's a MySQL/MariaDB specific type.
Collaborator
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. classic |
||
| "java.math.BigInteger", | ||
| typeOf<BigInteger>(), | ||
| ) | ||
|
|
||
| val types: List<ColumnType> = listOf( | ||
| BIGINT_UNSIGNED, | ||
| ) | ||
|
|
||
| @Test | ||
| fun `all MariaDB SQL types should match expected type`() { | ||
| types.forEach { type -> | ||
| MySql.getExpectedJdbcType(type.mockkColMetaData()) shouldBe type.expectedKotlinType | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
since when does "mock" have 2 k's? ;P
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.
oh and "metadata" is one word, so it would become: "mockColMetadata()"
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.
Because I often use MockK variables usually called
mockk..😆