Skip to content
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
8 changes: 4 additions & 4 deletions src/main/scala/com/rawlabs/das/sqlite/DASSqliteBackend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
val tableMap = scala.collection.mutable.Map.empty[String, DASSqliteTable]

while (rs.next()) {
val tableName = rs.getString("name").toLowerCase
val tableName = rs.getString("name")
val pkOpt = primaryKey(conn, tableName)
val tdef = tableDefinition(conn, tableName)
tableMap += tableName -> new DASSqliteTable(this, tdef, pkOpt)
Expand Down Expand Up @@ -141,7 +141,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
val colCount = meta.getColumnCount

for (i <- 1 to colCount) {
val colName = meta.getColumnName(i).toLowerCase
val colName = meta.getColumnName(i)
val value = toDASValue(rs, i)
rowBuilder.addColumns(Column.newBuilder().setName(colName).setData(value).build())
}
Expand Down Expand Up @@ -301,7 +301,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
val meta = rs.getMetaData
val colCount = meta.getColumnCount
for (i <- 1 to colCount) {
val colName = meta.getColumnName(i).toLowerCase
val colName = meta.getColumnName(i)
val value = toDASValue(rs, i)
rowBuilder.addColumns(
Column
Expand Down Expand Up @@ -341,7 +341,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
pkColumns += rs.getString("name")
}
}
if (pkColumns.size == 1) Some(pkColumns.head.toLowerCase)
if (pkColumns.size == 1) Some(pkColumns.head)
else None
}
}
Expand Down
Binary file added src/test/resources/mydb
Binary file not shown.
80 changes: 80 additions & 0 deletions src/test/scala/com/rawlabs/das/sqlite/DASSqliteSimpleTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2025 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

package com.rawlabs.das.sqlite

import scala.jdk.CollectionConverters._

import org.scalatest.BeforeAndAfterAll
import org.scalatest.funsuite.AnyFunSuite

import com.rawlabs.protocol.das.v1.tables.{Column, Row}
import com.rawlabs.protocol.das.v1.types.{Value, ValueDouble, ValueInt, ValueString}
import com.typesafe.scalalogging.StrictLogging

class DASSqliteSimpleTest extends AnyFunSuite with BeforeAndAfterAll with StrictLogging {

test("read mydb file") {
val resourceUrl = getClass.getResource("/mydb")
val file = new java.io.File(resourceUrl.toURI)
val fullPath = file.getAbsolutePath

val sdk = new DASSqlite(Map("database" -> fullPath))
val defs = sdk.tableDefinitions
assert(defs.nonEmpty, "tableDefinitions should not be empty.")
val names = defs.map(_.getTableId.getName)
assert(names.contains("COMPANY"), "We expect 'COMPANY' table in the DB.")

val columns = defs.find(_.getTableId.getName == "COMPANY").get.getColumnsList.asScala
assert(columns.map(_.getName) == Seq("ID", "NAME", "AGE", "ADDRESS", "SALARY"), "Columns should match.")

val rs =
sdk.getTable("COMPANY").get.execute(Seq.empty, Seq("ID", "NAME", "AGE", "ADDRESS", "SALARY"), Seq.empty, None)
val buf = scala.collection.mutable.ListBuffer[Row]()
while (rs.hasNext) {
buf += rs.next()
}
rs.close()

assert(
buf.toList == List(
buildMyDbRow(1, "Paul", 32, "California", 20000.0),
buildMyDbRow(2, "Allen", 25, "Texas", 15000.0),
buildMyDbRow(3, "Teddy", 23, "Norway", 20000.0),
buildMyDbRow(4, "Mark", 25, "Rich-Mond ", 65000.0),
buildMyDbRow(5, "David", 27, "Texas", 85000.0),
buildMyDbRow(6, "Kim", 22, "South-Hall", 45000.0)))

sdk.close()
}

private def buildMyDbRow(id: Int, name: String, age: Int, address: String, salary: Double): Row = {
val row = Row.newBuilder()
row.addColumns(Column.newBuilder().setName("ID").setData(Value.newBuilder().setInt(ValueInt.newBuilder().setV(id))))
row.addColumns(
Column.newBuilder().setName("NAME").setData(Value.newBuilder().setString(ValueString.newBuilder().setV(name))))
row.addColumns(
Column.newBuilder().setName("AGE").setData(Value.newBuilder().setInt(ValueInt.newBuilder().setV(age))))
row.addColumns(
Column
.newBuilder()
.setName("ADDRESS")
.setData(Value.newBuilder().setString(ValueString.newBuilder().setV(address))))
row.addColumns(
Column
.newBuilder()
.setName("SALARY")
.setData(Value.newBuilder().setDouble(ValueDouble.newBuilder().setV(salary))))
row.build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DASSqliteTableTest extends AnyFunSuite with BeforeAndAfterAll with StrictL
test("DASSqlite.tableDefinitions returns our test table") {
val defs = sdk.tableDefinitions
assert(defs.nonEmpty, "tableDefinitions should not be empty.")
val names = defs.map(_.getTableId.getName.toLowerCase)
val names = defs.map(_.getTableId.getName)
assert(names.contains("all_types"), "We expect 'all_types' table in the DB.")
}

Expand All @@ -143,7 +143,7 @@ class DASSqliteTableTest extends AnyFunSuite with BeforeAndAfterAll with StrictL
assert(defn.getTableId.getName.equalsIgnoreCase("all_types"), "Expected table name 'all_types'")
assert(defn.getColumnsCount > 0, "We expect at least 1 column in the schema.")

val columnNames = defn.getColumnsList.asScala.map(_.getName.toLowerCase).toSet
val columnNames = defn.getColumnsList.asScala.map(_.getName).toSet
val expectedSomeColumns = Set(
"id",
"col_integer",
Expand Down
Loading