Skip to content

Commit

Permalink
Action sbt scalafmtAll
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Jan 26, 2025
1 parent 44ebfb6 commit 60923e0
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import java.util.{ Locale, StringTokenizer }

import scala.collection.immutable.{ ListMap, SortedMap }

import scodec.bits.BitVector

import cats.*
import cats.syntax.all.*

import cats.effect.*

import scodec.bits.BitVector

import org.typelevel.otel4s.trace.Tracer

import ldbc.sql.{ Connection, DatabaseMetaData, PreparedStatement, ResultSet, RowIdLifetime, Statement }
Expand Down Expand Up @@ -1499,7 +1499,11 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
override def columnType: ColumnDataType = ColumnDataType.MYSQL_TYPE_VARCHAR
override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
},
dbList.map(name => ResultSetRowPacket(Array(BitVector.encodeUtf8("def").toOption, BitVector.encodeUtf8(name).toOption))).toVector,
dbList
.map(name =>
ResultSetRowPacket(Array(BitVector.encodeUtf8("def").toOption, BitVector.encodeUtf8(name).toOption))
)
.toVector,
serverVariables,
protocol.initialPacket.serverVersion
)
Expand Down Expand Up @@ -1909,8 +1913,8 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
(
mysqlType match
case MysqlType.BIGINT | MysqlType.BIGINT_UNSIGNED | MysqlType.BOOLEAN | MysqlType.INT |
MysqlType.INT_UNSIGNED | MysqlType.MEDIUMINT | MysqlType.MEDIUMINT_UNSIGNED | MysqlType.SMALLINT |
MysqlType.SMALLINT_UNSIGNED | MysqlType.TINYINT | MysqlType.TINYINT_UNSIGNED =>
MysqlType.INT_UNSIGNED | MysqlType.MEDIUMINT | MysqlType.MEDIUMINT_UNSIGNED |
MysqlType.SMALLINT | MysqlType.SMALLINT_UNSIGNED | MysqlType.TINYINT | MysqlType.TINYINT_UNSIGNED =>
Some("true")
case MysqlType.DOUBLE | MysqlType.DOUBLE_UNSIGNED | MysqlType.FLOAT | MysqlType.FLOAT_UNSIGNED =>
val supportsAutoIncrement = protocol.initialPacket.serverVersion.compare(Version(8, 4, 0)) >= 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private[ldbc] case class ResultSetImpl(
rowDecode[Byte](columnIndex - 1) match
case Some(value) =>
lastColumnReadNullable = false
value//.toByte(false)
value // .toByte(false)
case None =>
lastColumnReadNullable = true
0
Expand Down Expand Up @@ -398,8 +398,8 @@ private[ldbc] case class ResultSetImpl(

private def rowDecode[T](index: Int)(using codec: Codec[T]): Option[T] =
for
row <- currentRow
value <- row.values(index)
row <- currentRow
value <- row.values(index)
decoded <- codec.decode(value).toOption
yield decoded.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait NumericCodecs:
given Codec[BigDecimal] =
Codec[String].xmap(
str => BigDecimal(str),
_.toString(),
_.toString()
)

object numeric extends NumericCodecs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ import java.time.OffsetDateTime
import java.time.OffsetTime
import java.time.Year

import cats.syntax.all.*
import scodec.{ Attempt, Codec, Err }

import scodec.{Codec, Attempt, Err}
import cats.syntax.all.*

import ldbc.connector.data.Formatter.*

trait TemporalCodecs:

private def temporal[A <: TemporalAccessor](
formatter: DateTimeFormatter,
parse: (String, DateTimeFormatter) => A,
parse: (String, DateTimeFormatter) => A
): Codec[A] =
Codec[String].exmap(
str => Attempt.fromEither(Either.catchOnly[DateTimeParseException](parse(str, formatter)).leftMap(Err.fromThrowable(_))),
str =>
Attempt.fromEither(
Either.catchOnly[DateTimeParseException](parse(str, formatter)).leftMap(Err.fromThrowable(_))
),
temporal => Attempt.successful(formatter.format(temporal))
)

Expand Down Expand Up @@ -58,29 +61,31 @@ trait TemporalCodecs:
)
def year(digit: 4): Codec[Year] =
Codec[String].exmap(
str => Attempt.fromEither(Either.catchOnly[DateTimeParseException](Year.parse(str)).leftMap(Err.fromThrowable(_))),
year => Attempt.successful(year.toString),
str =>
Attempt.fromEither(Either.catchOnly[DateTimeParseException](Year.parse(str)).leftMap(Err.fromThrowable(_))),
year => Attempt.successful(year.toString)
)
given Codec[Year] =
Codec[String].exmap(
str => Attempt.fromEither(
(
for
int <- Either.catchOnly[NumberFormatException](str.toInt)
year <- Either.catchOnly[DateTimeParseException] {
val int = str.toInt
if (1901 <= int && int <= 2156) || str === "0000" then Year.of(int)
else
throw new DateTimeParseException(
s"Year is out of range: $int. Year must be in the range 1901 to 2155.",
str,
0
)
}
yield year
str =>
Attempt.fromEither(
(
for
int <- Either.catchOnly[NumberFormatException](str.toInt)
year <- Either.catchOnly[DateTimeParseException] {
val int = str.toInt
if (1901 <= int && int <= 2156) || str === "0000" then Year.of(int)
else
throw new DateTimeParseException(
s"Year is out of range: $int. Year must be in the range 1901 to 2155.",
str,
0
)
}
yield year
).leftMap(Err.fromThrowable(_))
),
year => Attempt.successful(year.toString),
),
year => Attempt.successful(year.toString)
)

object temporal extends TemporalCodecs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait TextCodecs:
def binary(): Codec[Array[Byte]] =
Codec[String].xmap(
s => s.getBytes("UTF-8"),
bytes => new String(bytes),
bytes => new String(bytes)
)
given Codec[Array[Byte]] = binary()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ object Protocol:
yield columnDefinitions
.zip(resultSetRow.flatMap(_.values))
.map {
case (columnDefinition, resultSetRow) => columnDefinition.name -> resultSetRow.map(_.toBase64).getOrElse("")
case (columnDefinition, resultSetRow) =>
columnDefinition.name -> resultSetRow.map(_.toBase64).getOrElse("")
}
.toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ object BinaryProtocolResultSetRowPacket:
case MYSQL_TYPE_DOUBLE => doubleL.map(d => BitVector.encodeUtf8(d.toString).toOption)
case MYSQL_TYPE_FLOAT => floatL.map(f => BitVector.encodeUtf8(f.toString).toOption)
case MYSQL_TYPE_DATE =>
timestamp.map(_.flatMap(localDateTime => BitVector.encodeUtf8(localDateFormatter.format(localDateTime.toLocalDate)).toOption))
case MYSQL_TYPE_DATETIME | MYSQL_TYPE_TIMESTAMP => timestamp.map(_.flatMap(localDateTime => BitVector.encodeUtf8(localDateTimeFormatter(0).format(localDateTime)).toOption))
case MYSQL_TYPE_TIME => time.map(_.flatMap(localDateTime => BitVector.encodeUtf8(timeFormatter(0).format(localDateTime)).toOption))
case MYSQL_TYPE_NULL => provide(None)
timestamp.map(
_.flatMap(localDateTime =>
BitVector.encodeUtf8(localDateFormatter.format(localDateTime.toLocalDate)).toOption
)
)
case MYSQL_TYPE_DATETIME | MYSQL_TYPE_TIMESTAMP =>
timestamp.map(
_.flatMap(localDateTime => BitVector.encodeUtf8(localDateTimeFormatter(0).format(localDateTime)).toOption)
)
case MYSQL_TYPE_TIME =>
time.map(_.flatMap(localDateTime => BitVector.encodeUtf8(timeFormatter(0).format(localDateTime)).toOption))
case MYSQL_TYPE_NULL => provide(None)
case MYSQL_TYPE_NEWDATE | MYSQL_TYPE_TIMESTAMP2 | MYSQL_TYPE_DATETIME2 | MYSQL_TYPE_TIME2 | MYSQL_TYPE_JSON =>
throw new RuntimeException(s"Unsupported column type: ${ column.columnType }")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
package ldbc.connector.net.packet
package response

import scodec.Decoder
import scodec.bits.BitVector
import scodec.codecs.*
import scodec.Decoder

import cats.syntax.all.*

Expand Down Expand Up @@ -53,19 +53,22 @@ object ResultSetRowPacket:
case ERRPacket.STATUS => ERRPacket.decoder(capabilityFlags)
case length =>
val buffer = new Array[Option[BitVector]](columns.length)
columns.zipWithIndex.foldLeft(Decoder.pure(buffer)) {
case (acc, (column, index)) =>
val valueDecoder =
if length == NULL && index == 0 then Decoder.pure(None)
else if index == 0 then decodeValue(length)
else lengthEncodedIntDecoder.flatMap {
case NULL => Decoder.pure(None)
case value => decodeValue(value.toInt)
}
columns.zipWithIndex
.foldLeft(Decoder.pure(buffer)) {
case (acc, (column, index)) =>
val valueDecoder =
if length == NULL && index == 0 then Decoder.pure(None)
else if index == 0 then decodeValue(length)
else
lengthEncodedIntDecoder.flatMap {
case NULL => Decoder.pure(None)
case value => decodeValue(value.toInt)
}

for
buffer <- acc
value <- valueDecoder
yield buffer.updated(index, value)
}.map(ResultSetRowPacket(_))
for
buffer <- acc
value <- valueDecoder
yield buffer.updated(index, value)
}
.map(ResultSetRowPacket(_))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import java.time.*

import scala.collection.immutable.{ ListMap, SortedMap }

import scodec.bits.BitVector

import cats.*
import cats.syntax.all.*

import cats.effect.*

import scodec.bits.BitVector

import org.typelevel.otel4s.trace.{ Span, Tracer }
import org.typelevel.otel4s.Attribute

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ package ldbc.connector.net.protocol

import scala.collection.immutable.{ ListMap, SortedMap }

import scodec.bits.BitVector

import cats.*
import cats.syntax.all.*

import cats.effect.*

import scodec.bits.BitVector

import org.typelevel.otel4s.trace.{ Span, Tracer }
import org.typelevel.otel4s.Attribute

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ package ldbc.connector.net.protocol

import scala.collection.immutable.{ ListMap, SortedMap }

import scodec.bits.BitVector

import cats.*
import cats.syntax.all.*

import cats.effect.*

import scodec.bits.BitVector

import org.typelevel.otel4s.trace.{ Span, Tracer }
import org.typelevel.otel4s.Attribute

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ package ldbc.connector.net.protocol

import scala.collection.immutable.ListMap

import scodec.bits.BitVector

import cats.*
import cats.syntax.all.*

import cats.effect.*

import scodec.bits.BitVector

import org.typelevel.otel4s.trace.{ Span, Tracer }
import org.typelevel.otel4s.Attribute

Expand Down

0 comments on commit 60923e0

Please sign in to comment.