Skip to content
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

Refactor/2024 07 changing collection types for result set row packet #263

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](

override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
},
dbList.map(name => ResultSetRowPacket(List(Some(name)))).toVector,
dbList.map(name => ResultSetRowPacket(Array(Some(name)))).toVector,
serverVariables,
protocol.initialPacket.serverVersion,
isResultSetClosed,
Expand Down Expand Up @@ -571,7 +571,7 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
),
TableType.values
.filterNot(_ == TableType.UNKNOWN)
.map(tableType => ResultSetRowPacket(List(Some(tableType.name))))
.map(tableType => ResultSetRowPacket(Array(Some(tableType.name))))
.toVector,
serverVariables,
protocol.initialPacket.serverVersion,
Expand Down Expand Up @@ -935,7 +935,7 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
decoded.flatten.map {
case (scope, columnName, dataType, typeName, columnSize, bufferLength, decimalDigits, pseudoColumn) =>
ResultSetRowPacket(
List(
Array(
Some(scope.toString),
Some(columnName),
Some(dataType.toString),
Expand Down Expand Up @@ -1433,7 +1433,7 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](

override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
},
dbList.map(name => ResultSetRowPacket(List(Some("def"), Some(name)))).toVector,
dbList.map(name => ResultSetRowPacket(Array(Some("def"), Some(name)))).toVector,
serverVariables,
protocol.initialPacket.serverVersion,
isResultSetClosed,
Expand Down Expand Up @@ -1809,10 +1809,10 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
"JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS R ON (R.CONSTRAINT_NAME = B.CONSTRAINT_NAME "
+ "AND R.TABLE_NAME = B.TABLE_NAME AND R.CONSTRAINT_SCHEMA = B.TABLE_SCHEMA) "

private def getTypeInfo(mysqlTypeName: String): List[Option[String]] =
private def getTypeInfo(mysqlTypeName: String): Array[Option[String]] =
val mysqlType = MysqlType.getByName(mysqlTypeName)

List(
Array(
Some(mysqlTypeName), // TYPE_NAME
if mysqlType == MysqlType.YEAR && !yearIsDateType then Some(SMALLINT.toString)
else Some(mysqlType.jdbcType.toString), // DATA_TYPE
Expand All @@ -1825,9 +1825,9 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
MysqlType.TEXT | MysqlType.MEDIUMTEXT | MysqlType.LONGTEXT | MysqlType.JSON | MysqlType.BINARY |
MysqlType.VARBINARY | MysqlType.CHAR | MysqlType.VARCHAR | MysqlType.ENUM | MysqlType.SET | MysqlType.DATE |
MysqlType.TIME | MysqlType.DATETIME | MysqlType.TIMESTAMP | MysqlType.GEOMETRY | MysqlType.UNKNOWN =>
List(Some("'"), Some("'"))
case _ => List(Some(""), Some(""))
) ++ List(
Array(Some("'"), Some("'"))
case _ => Array(Some(""), Some(""))
) ++ Array(
Some(mysqlType.createParams), // CREATE_PARAMS
Some(DatabaseMetaData.typeNullable.toString), // NULLABLE
Some("true"), // CASE_SENSITIVE
Expand All @@ -1849,11 +1849,11 @@ private[ldbc] case class DatabaseMetaDataImpl[F[_]: Temporal: Exchange: Tracer](
// MINIMUM_SCALE, MAXIMUM_SCALE
mysqlType match
case MysqlType.DECIMAL | MysqlType.DECIMAL_UNSIGNED | MysqlType.DOUBLE | MysqlType.DOUBLE_UNSIGNED =>
List(Some("-308"), Some("308"))
Array(Some("-308"), Some("308"))
case MysqlType.FLOAT | MysqlType.FLOAT_UNSIGNED =>
List(Some("-38"), Some("38"))
case _ => List(Some("0"), Some("0"))
) ++ List(
Array(Some("-38"), Some("38"))
case _ => Array(Some("0"), Some("0"))
) ++ Array(
Some("0"), // SQL_DATA_TYPE
Some("0"), // SQL_DATETIME_SUB
Some("10") // NUM_PREC_RADIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private[ldbc] case class ResultSetImpl[F[_]](
def decode[T](codec: Codec[T]): F[List[T]] =
checkClose {
ev.point(
records.flatMap(row => codec.decode(0, row.values).toOption).toList
records.flatMap(row => codec.decode(0, row.values.toList).toOption).toList
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ldbc.connector.data.CapabilitiesFlags
import ldbc.connector.data.ColumnDataType.*
import ldbc.connector.data.Formatter.*

case class BinaryProtocolResultSetRowPacket(values: List[Option[String]]) extends ResultSetRowPacket:
case class BinaryProtocolResultSetRowPacket(values: Array[Option[String]]) extends ResultSetRowPacket:

override def toString: String = "Binary Protocol ResultSet Row"

Expand Down Expand Up @@ -60,5 +60,5 @@ object BinaryProtocolResultSetRowPacket:
val isColumnNull = (nullBitmapBytes((index + 2) / 8) & (1 << ((index + 2) % 8))) != 0
decodeValue(column, isColumnNull)
}
yield BinaryProtocolResultSetRowPacket(values.toList)
yield BinaryProtocolResultSetRowPacket(values.toArray)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
package ldbc.connector.net.packet
package response

import scala.collection.mutable.ArrayBuffer

import cats.syntax.all.*

import scodec.*
Expand All @@ -30,17 +28,17 @@ trait ResultSetRowPacket extends ResponsePacket:
/**
* The values of the row.
*/
def values: List[Option[String]]
def values: Array[Option[String]]

override def toString: String = s"ProtocolText::ResultSetRow"
override def toString: String = "ProtocolText::ResultSetRow"

object ResultSetRowPacket:

private val NULL = 0xfb

def apply(_values: List[Option[String]]): ResultSetRowPacket =
def apply(_values: Array[Option[String]]): ResultSetRowPacket =
new ResultSetRowPacket:
override val values: List[Option[String]] = _values
override val values: Array[Option[String]] = _values

private def decodeValue(length: Int): Decoder[Option[String]] =
bytes(length).asDecoder
Expand All @@ -54,24 +52,25 @@ object ResultSetRowPacket:
case EOFPacket.STATUS => EOFPacket.decoder(capabilityFlags)
case ERRPacket.STATUS => ERRPacket.decoder(capabilityFlags)
case length =>
columns.zipWithIndex
.foldLeft(Decoder.pure(ArrayBuffer.empty[Option[String]])) {
case (acc, (column, index)) =>
acc.flatMap { buffer =>
val valueDecoder = length match
case NULL if index == 0 => Decoder.pure(None)
case _ if index == 0 => decodeValue(length)
case _ =>
lengthEncodedIntDecoder.flatMap {
case NULL => Decoder.pure(None)
case value => decodeValue(value.toInt)
}
val buffer = new Array[Option[String]](columns.length)

def decodeRow(index: Int, remainingLength: Option[Int]): Decoder[ResultSetRowPacket] =
if index >= columns.length then Decoder.pure(ResultSetRowPacket(buffer))
else
val valueDecoder =
length match
case NULL if index == 0 => Decoder.pure(None)
case _ if index == 0 => decodeValue(length)
case _ =>
lengthEncodedIntDecoder.flatMap {
case NULL => Decoder.pure(None)
case value => decodeValue(value.toInt)
}

valueDecoder.flatMap { value =>
buffer(index) = value
decodeRow(index + 1, None)
}

valueDecoder.map { value =>
buffer.append(value)
buffer
}
}
}
.map(array => ResultSetRowPacket(array.toList))
decodeRow(0, Some(length))
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ case class CallableStatementImpl[F[_]: Temporal: Exchange: Tracer](

override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
),
Vector(ResultSetRowPacket(List(Some(lastInsertId.toString)))),
Vector(ResultSetRowPacket(Array(Some(lastInsertId.toString)))),
serverVariables,
protocol.initialPacket.serverVersion,
isResultSetClosed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ case class ClientPreparedStatement[F[_]: Temporal: Exchange: Tracer](

override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
),
Vector(ResultSetRowPacket(List(Some(lastInsertId.toString)))),
Vector(ResultSetRowPacket(Array(Some(lastInsertId.toString)))),
serverVariables,
protocol.initialPacket.serverVersion,
isResultSetClosed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ case class ServerPreparedStatement[F[_]: Temporal: Exchange: Tracer](

override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
),
Vector(ResultSetRowPacket(List(Some(lastInsertId.toString)))),
Vector(ResultSetRowPacket(Array(Some(lastInsertId.toString)))),
serverVariables,
protocol.initialPacket.serverVersion,
isResultSetClosed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private[ldbc] case class StatementImpl[F[_]: Temporal: Exchange: Tracer](

override def flags: Seq[ColumnDefinitionFlags] = Seq.empty
),
Vector(ResultSetRowPacket(List(Some(lastInsertId.toString)))),
Vector(ResultSetRowPacket(Array(Some(lastInsertId.toString)))),
serverVariables,
protocol.initialPacket.serverVersion,
isResultSetClosed,
Expand Down
Loading