Skip to content

Commit 30ea094

Browse files
Fix to case errors
1 parent 8c953af commit 30ea094

File tree

4 files changed

+89
-6
lines changed

4 files changed

+89
-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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2024 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+
// ===========================================================================
27+
// Tests for DASSqlite (top-level) methods
28+
// ===========================================================================
29+
test("read mydb file") {
30+
val resourceUrl = getClass.getResource("/mydb")
31+
val file = new java.io.File(resourceUrl.toURI)
32+
val fullPath = file.getAbsolutePath
33+
34+
val sdk = new DASSqlite(Map("database" -> fullPath))
35+
val defs = sdk.tableDefinitions
36+
assert(defs.nonEmpty, "tableDefinitions should not be empty.")
37+
val names = defs.map(_.getTableId.getName)
38+
assert(names.contains("COMPANY"), "We expect 'COMPANY' table in the DB.")
39+
40+
val columns = defs.find(_.getTableId.getName == "COMPANY").get.getColumnsList.asScala
41+
assert(columns.map(_.getName) == Seq("ID", "NAME", "AGE", "ADDRESS", "SALARY"), "Columns should match.")
42+
43+
val rs =
44+
sdk.getTable("COMPANY").get.execute(Seq.empty, Seq("ID", "NAME", "AGE", "ADDRESS", "SALARY"), Seq.empty, None)
45+
val buf = scala.collection.mutable.ListBuffer[Row]()
46+
while (rs.hasNext) {
47+
buf += rs.next()
48+
}
49+
rs.close()
50+
51+
assert(
52+
buf.toList == List(
53+
buildMyDbRow(1, "Paul", 32, "California", 20000.0),
54+
buildMyDbRow(2, "Allen", 25, "Texas", 15000.0),
55+
buildMyDbRow(3, "Teddy", 23, "Norway", 20000.0),
56+
buildMyDbRow(4, "Mark", 25, "Rich-Mond ", 65000.0),
57+
buildMyDbRow(5, "David", 27, "Texas", 85000.0),
58+
buildMyDbRow(6, "Kim", 22, "South-Hall", 45000.0)))
59+
60+
sdk.close()
61+
}
62+
63+
private def buildMyDbRow(id: Int, name: String, age: Int, address: String, salary: Double): Row = {
64+
val row = Row.newBuilder()
65+
row.addColumns(Column.newBuilder().setName("ID").setData(Value.newBuilder().setInt(ValueInt.newBuilder().setV(id))))
66+
row.addColumns(
67+
Column.newBuilder().setName("NAME").setData(Value.newBuilder().setString(ValueString.newBuilder().setV(name))))
68+
row.addColumns(
69+
Column.newBuilder().setName("AGE").setData(Value.newBuilder().setInt(ValueInt.newBuilder().setV(age))))
70+
row.addColumns(
71+
Column
72+
.newBuilder()
73+
.setName("ADDRESS")
74+
.setData(Value.newBuilder().setString(ValueString.newBuilder().setV(address))))
75+
row.addColumns(
76+
Column
77+
.newBuilder()
78+
.setName("SALARY")
79+
.setData(Value.newBuilder().setDouble(ValueDouble.newBuilder().setV(salary))))
80+
row.build()
81+
}
82+
83+
}

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)