Skip to content

Commit 68e65bf

Browse files
Merge pull request #2 from raw-labs/fix-to-cases
Fix to case errors
2 parents 8c953af + 0d3a5a0 commit 68e65bf

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

src/main/scala/com/rawlabs/das/sqlite/DASSqliteBackend.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
7777
val tableMap = scala.collection.mutable.Map.empty[String, DASSqliteTable]
7878

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

143143
for (i <- 1 to colCount) {
144-
val colName = meta.getColumnName(i).toLowerCase
144+
val colName = meta.getColumnName(i)
145145
val value = toDASValue(rs, i)
146146
rowBuilder.addColumns(Column.newBuilder().setName(colName).setData(value).build())
147147
}
@@ -301,7 +301,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
301301
val meta = rs.getMetaData
302302
val colCount = meta.getColumnCount
303303
for (i <- 1 to colCount) {
304-
val colName = meta.getColumnName(i).toLowerCase
304+
val colName = meta.getColumnName(i)
305305
val value = toDASValue(rs, i)
306306
rowBuilder.addColumns(
307307
Column
@@ -341,7 +341,7 @@ private class DASSqliteBackend(dataSource: DataSource) extends StrictLogging {
341341
pkColumns += rs.getString("name")
342342
}
343343
}
344-
if (pkColumns.size == 1) Some(pkColumns.head.toLowerCase)
344+
if (pkColumns.size == 1) Some(pkColumns.head)
345345
else None
346346
}
347347
}

src/test/resources/mydb

3 KB
Binary file not shown.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2025 RAW Labs S.A.
3+
*
4+
* Use of this software is governed by the Business Source License
5+
* included in the file licenses/BSL.txt.
6+
*
7+
* As of the Change Date specified in that file, in accordance with
8+
* the Business Source License, use of this software will be governed
9+
* by the Apache License, Version 2.0, included in the file
10+
* licenses/APL.txt.
11+
*/
12+
13+
package com.rawlabs.das.sqlite
14+
15+
import scala.jdk.CollectionConverters._
16+
17+
import org.scalatest.BeforeAndAfterAll
18+
import org.scalatest.funsuite.AnyFunSuite
19+
20+
import com.rawlabs.protocol.das.v1.tables.{Column, Row}
21+
import com.rawlabs.protocol.das.v1.types.{Value, ValueDouble, ValueInt, ValueString}
22+
import com.typesafe.scalalogging.StrictLogging
23+
24+
class DASSqliteSimpleTest extends AnyFunSuite with BeforeAndAfterAll with StrictLogging {
25+
26+
test("read mydb file") {
27+
val resourceUrl = getClass.getResource("/mydb")
28+
val file = new java.io.File(resourceUrl.toURI)
29+
val fullPath = file.getAbsolutePath
30+
31+
val sdk = new DASSqlite(Map("database" -> fullPath))
32+
val defs = sdk.tableDefinitions
33+
assert(defs.nonEmpty, "tableDefinitions should not be empty.")
34+
val names = defs.map(_.getTableId.getName)
35+
assert(names.contains("COMPANY"), "We expect 'COMPANY' table in the DB.")
36+
37+
val columns = defs.find(_.getTableId.getName == "COMPANY").get.getColumnsList.asScala
38+
assert(columns.map(_.getName) == Seq("ID", "NAME", "AGE", "ADDRESS", "SALARY"), "Columns should match.")
39+
40+
val rs =
41+
sdk.getTable("COMPANY").get.execute(Seq.empty, Seq("ID", "NAME", "AGE", "ADDRESS", "SALARY"), Seq.empty, None)
42+
val buf = scala.collection.mutable.ListBuffer[Row]()
43+
while (rs.hasNext) {
44+
buf += rs.next()
45+
}
46+
rs.close()
47+
48+
assert(
49+
buf.toList == List(
50+
buildMyDbRow(1, "Paul", 32, "California", 20000.0),
51+
buildMyDbRow(2, "Allen", 25, "Texas", 15000.0),
52+
buildMyDbRow(3, "Teddy", 23, "Norway", 20000.0),
53+
buildMyDbRow(4, "Mark", 25, "Rich-Mond ", 65000.0),
54+
buildMyDbRow(5, "David", 27, "Texas", 85000.0),
55+
buildMyDbRow(6, "Kim", 22, "South-Hall", 45000.0)))
56+
57+
sdk.close()
58+
}
59+
60+
private def buildMyDbRow(id: Int, name: String, age: Int, address: String, salary: Double): Row = {
61+
val row = Row.newBuilder()
62+
row.addColumns(Column.newBuilder().setName("ID").setData(Value.newBuilder().setInt(ValueInt.newBuilder().setV(id))))
63+
row.addColumns(
64+
Column.newBuilder().setName("NAME").setData(Value.newBuilder().setString(ValueString.newBuilder().setV(name))))
65+
row.addColumns(
66+
Column.newBuilder().setName("AGE").setData(Value.newBuilder().setInt(ValueInt.newBuilder().setV(age))))
67+
row.addColumns(
68+
Column
69+
.newBuilder()
70+
.setName("ADDRESS")
71+
.setData(Value.newBuilder().setString(ValueString.newBuilder().setV(address))))
72+
row.addColumns(
73+
Column
74+
.newBuilder()
75+
.setName("SALARY")
76+
.setData(Value.newBuilder().setDouble(ValueDouble.newBuilder().setV(salary))))
77+
row.build()
78+
}
79+
80+
}

src/test/scala/com/rawlabs/das/sqlite/DASSqliteTableTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class DASSqliteTableTest extends AnyFunSuite with BeforeAndAfterAll with StrictL
116116
test("DASSqlite.tableDefinitions returns our test table") {
117117
val defs = sdk.tableDefinitions
118118
assert(defs.nonEmpty, "tableDefinitions should not be empty.")
119-
val names = defs.map(_.getTableId.getName.toLowerCase)
119+
val names = defs.map(_.getTableId.getName)
120120
assert(names.contains("all_types"), "We expect 'all_types' table in the DB.")
121121
}
122122

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

146-
val columnNames = defn.getColumnsList.asScala.map(_.getName.toLowerCase).toSet
146+
val columnNames = defn.getColumnsList.asScala.map(_.getName).toSet
147147
val expectedSomeColumns = Set(
148148
"id",
149149
"col_integer",

0 commit comments

Comments
 (0)