Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Truncate long VARCHAR fields before casting (close #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuwy committed Oct 1, 2020
1 parent 535b4a1 commit 33eea4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ package object ast {

implicit object CastedColumnShow extends Show[Select.CastedColumn] {
def show(column: Select.CastedColumn): String = {
val castedColumn = s"${column.originColumn}:${column.columnName}::${column.datatype.show}"
column.substring match {
case Some(Substring(start, length)) => s"substr($castedColumn,$start,$length)"
case None => castedColumn
case Some(Substring(start, length)) =>
val columnName = s"${column.originColumn}:${column.columnName}"
s"substr($columnName,$start,$length)::${column.datatype.show}"
case None =>
s"${column.originColumn}:${column.columnName}::${column.datatype.show}"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class StatementSpec extends Specification {

val result = input.getStatement.value
val expected = "INSERT INTO not_atomic.events(one,two,three) " +
"SELECT orig_col:dest_column::VARIANT, orig_col:next::DOUBLE PRECISION, substr(orig_col:third::NUMBER(1,2),1,255) " +
"SELECT orig_col:dest_column::VARIANT, orig_col:next::DOUBLE PRECISION, substr(orig_col:third,1,255)::NUMBER(1,2) " +
"FROM some_schema.tmp_table"

result must beEqualTo(expected)
Expand Down

0 comments on commit 33eea4f

Please sign in to comment.