-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from caraml-dev/add-custom-dialect-workflow
feat: add source and build for custom dialect
- Loading branch information
Showing
3 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,56 @@ | ||
name: Publish CustomDialect JAR | ||
|
||
on: | ||
workflow_dispatch: # Allows manual triggering of the workflow | ||
push: | ||
tags: | ||
- "caraml-store-spark/odps/v[0-9]+.[0-9]+.[0-9]+*" | ||
paths: | ||
- ".github/workflows/odps.yaml" | ||
- "caraml-store-spark/src/main/scala/dev/caraml/spark/odps/**" | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: "17" | ||
distribution: "temurin" | ||
|
||
- name: Build customDialectJar | ||
uses: gradle/gradle-build-action@v2 | ||
with: | ||
arguments: customDialectJar | ||
|
||
- name: Publish customDialectJar | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: custom-dialect | ||
path: caraml-store-spark/build/libs/custom-dialect.jar | ||
|
||
- name: Create Draft Prerelease | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref_name }} | ||
release_name: Release ${{ github.ref_name }} | ||
draft: true | ||
prerelease: true | ||
|
||
- name: Upload customDialectJar to Release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: caraml-store-spark/build/libs/custom-dialect.jar | ||
asset_name: custom-dialect.jar | ||
asset_content_type: application/java-archive |
This file contains 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
44 changes: 44 additions & 0 deletions
44
caraml-store-spark/src/main/scala/dev/caraml/spark/odps/CustomDialect.scala
This file contains 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,44 @@ | ||
package dev.caraml.spark.odps | ||
import org.apache.spark.sql.jdbc.JdbcDialect | ||
import org.apache.spark.sql.jdbc.JdbcType | ||
import org.apache.spark.sql.types.DataType | ||
import org.apache.spark.sql.types._ | ||
import org.apache.hbase.thirdparty.org.eclipse.jetty.util.ajax.JSON | ||
|
||
class CustomDialect extends JdbcDialect { | ||
override def canHandle(url: String): Boolean = { | ||
url.startsWith("jdbc:odps") | ||
} | ||
|
||
override def quoteIdentifier(colName: String): String = { | ||
s"$colName" | ||
} | ||
|
||
override def getJDBCType(dt: DataType): Option[JdbcType] = { | ||
dt match { | ||
case IntegerType => Option(JdbcType("INTEGER", java.sql.Types.INTEGER)) | ||
case LongType => Option(JdbcType("BIGINT", java.sql.Types.BIGINT)) | ||
case DoubleType => | ||
Option(JdbcType("DOUBLE", java.sql.Types.DOUBLE)) | ||
case FloatType => Option(JdbcType("FLOAT", java.sql.Types.FLOAT)) | ||
case ShortType => Option(JdbcType("SMALLINT", java.sql.Types.SMALLINT)) | ||
case ByteType => Option(JdbcType("TINYINT", java.sql.Types.TINYINT)) | ||
case BooleanType => Option(JdbcType("BOOLEAN", java.sql.Types.BOOLEAN)) | ||
case StringType => Option(JdbcType("STRING", java.sql.Types.CLOB)) | ||
case BinaryType => Option(JdbcType("BINARY", java.sql.Types.BINARY)) | ||
case TimestampType => | ||
Option(JdbcType("TIMESTAMP", java.sql.Types.TIMESTAMP)) | ||
case DateType => Option(JdbcType("DATE", java.sql.Types.DATE)) | ||
case t: DecimalType => | ||
Option( | ||
JdbcType( | ||
s"DECIMAL(${t.precision},${t.scale})", | ||
java.sql.Types.DECIMAL | ||
) | ||
) | ||
case VarcharType(length) => Option(JdbcType(s"VARCHAR($length)", java.sql.Types.VARCHAR)) | ||
// NOTE: Update when necessary | ||
case _ => None | ||
} | ||
} | ||
} |