Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 committed Feb 3, 2025
1 parent 4b9a3fb commit 035393f
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
package com.rawlabs.sql.compiler.writers

import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.google.protobuf.ByteString
import com.rawlabs.compiler._
import com.rawlabs.protocol.raw._
import com.rawlabs.sql.compiler.SqlIntervals.stringToInterval
import com.typesafe.scalalogging.StrictLogging
import org.postgresql.util.{PGInterval, PGobject}

import java.sql.{ResultSet, Time, Timestamp}
import java.sql.{ResultSet, Timestamp}
import java.time.temporal.ChronoField
import scala.annotation.tailrec
import scala.collection.JavaConverters._
Expand Down Expand Up @@ -197,11 +198,21 @@ class TypedResultSetRawValueIterator(
intervalValue(interval)
}

case _: RawBinaryType =>
val bytes = rs.getBytes(colIndex)
if (rs.wasNull() || bytes == null) {
buildNullValue()
} else {
binaryValue(bytes)
}

case _: RawAnyType =>
// Single column typed as ANY
val colTypeName = rs.getMetaData.getColumnTypeName(colIndex).toLowerCase
// e.g. "json", "jsonb", "hstore", or something else
handleAnySingleValue(rs, colIndex, colTypeName)

case _ => throw new IllegalArgumentException(s"Unsupported type: $tipe")
}
}

Expand Down Expand Up @@ -284,6 +295,9 @@ class TypedResultSetRawValueIterator(
// fallback or error
stringValue(element.toString)
}

case _ => throw new IllegalArgumentException(s"Unsupported type: $tipe")

}
}

Expand Down Expand Up @@ -548,6 +562,19 @@ class TypedResultSetRawValueIterator(
.build()
}

private def binaryValue(bytes: Array[Byte]): Value = {
Value
.newBuilder()
.setBinary(
ValueBinary
.newBuilder()
.setV(
ByteString.copyFrom(bytes)
)
)
.build()
}

/**
* Close the underlying ResultSet. Typically you'd also close the Statement that created it.
*/
Expand Down

0 comments on commit 035393f

Please sign in to comment.