Skip to content

Commit 45d6559

Browse files
OmniaGMtabdulradi
authored andcommitted
#127 Add test cases to cover aggregates (#138)
1 parent 12661a3 commit 45d6559

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package troy.cql3_3.lexical
2+
3+
import org.scalatest.{ FlatSpec, Matchers }
4+
import troy.cql.ast.dml.Select._
5+
import troy.cql.parser.ParserTestUtils._
6+
7+
class DataManipulationParsingSpec extends FlatSpec with Matchers {
8+
"SELECT parser" should "parse asterisk" in {
9+
parseSelect("SELECT * FROM test;").selection shouldBe Asterisk
10+
}
11+
12+
it should "parse DISTINCT partition" in {
13+
parseSelect("SELECT DISTINCT * FROM test;").selection shouldBe Asterisk
14+
}
15+
16+
it should "parse JSON partition" in {
17+
parseSelect("SELECT JSON * FROM test;").mod.get shouldBe Json
18+
}
19+
20+
// TODO: https://github.com/cassandra-scala/troy/issues/134
21+
"Standard aggregates" should "parse count" in {
22+
val selectClause: SelectClause = parseSelect("SELECT COUNT(*) FROM test;").selection.asInstanceOf[SelectClause]
23+
selectClause.items(0).asInstanceOf[SelectionClauseItem].selector shouldBe Count
24+
}
25+
26+
it should "parse max" ignore {
27+
parseSelect("SELECT MAX(*) FROM test;")
28+
}
29+
30+
it should "parse min" ignore {
31+
parseSelect("SELECT MIN(*) FROM test;")
32+
}
33+
34+
it should "parse sum" ignore {
35+
parseSelect("SELECT SUM(*) FROM test;")
36+
}
37+
38+
it should "parse avg" ignore {
39+
parseSelect("SELECT AVG(*) FROM test;")
40+
}
41+
42+
// TODO: https://github.com/cassandra-scala/troy/issues/137
43+
"User-defined aggregate" should "be parsed" ignore {
44+
parseQuery("CREATE AGGREGATE min_value(double) SFUNC state_min_int STYPE double INITCOND null;")
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package troy.cql3_3.lexical
2+
3+
import org.scalatest._
4+
import troy.cql.ast.DataType
5+
import troy.schema.SchemaTestUtils._
6+
7+
class DataManipulationSchemaSpec extends FlatSpec with Matchers {
8+
implicit lazy val schema = buildSchema(
9+
"""
10+
| CREATE KEYSPACE specs WITH replication = {'class': 'SimpleStrategy' , 'replication_factor': '1'};
11+
| CREATE TABLE specs.test (
12+
| foo int PRIMARY KEY,
13+
| bar TEXT,
14+
| barfoo TEXT
15+
| );
16+
""".stripMargin
17+
)
18+
19+
// TODO: https://github.com/cassandra-scala/troy/issues/136
20+
"Schema" should "support select *" ignore {
21+
asteriskOf("SELECT * FROM specs.test;").size shouldBe 3
22+
}
23+
24+
it should "support select with DISTINCT partition" in {
25+
columnsOf("SELECT DISTINCT foo FROM specs.test;").head shouldBe DataType.Int
26+
}
27+
28+
it should "support select with JSON formate" in {
29+
columnsOf("SELECT JSON foo FROM specs.test;").head shouldBe DataType.Int
30+
}
31+
32+
// TODO: https://github.com/cassandra-scala/troy/issues/134
33+
it should "support select with count aggregate function" ignore {
34+
columnsOf("SELECT count(foo) FROM specs.test;").head shouldBe DataType.Int
35+
}
36+
37+
it should "support select with min aggregate function" ignore {
38+
columnsOf("SELECT min(foo) FROM specs.test;").head shouldBe DataType.Int
39+
}
40+
41+
it should "support select with max aggregate function" ignore {
42+
columnsOf("SELECT max(foo) FROM specs.test;").head shouldBe DataType.Int
43+
}
44+
45+
it should "support select with sum aggregate function" ignore {
46+
columnsOf("SELECT sum(foo) FROM specs.test;").head shouldBe DataType.Int
47+
}
48+
49+
it should "support select with avg aggregate function" ignore {
50+
columnsOf("SELECT avg(foo) FROM specs.test;").head shouldBe DataType.Int
51+
}
52+
53+
// TODO: https://github.com/cassandra-scala/troy/issues/137
54+
it should "support select with User-defined aggregate function" ignore {
55+
columnsOf("SELECT UDAggregate(foo) FROM specs.test;").head shouldBe DataType.Int
56+
}
57+
}

troy-schema/src/test/scala/troy/schema/SchemaTestUtils.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package troy.schema
22

33
import org.scalatest.{ FlatSpec, Matchers }
4-
import troy.cql.parser.ParserTestUtils.{ parseSchema, parseQuery }
4+
import troy.cql.parser.ParserTestUtils.{ parseQuery, parseSchema }
55
import VTestUtils._
6-
import troy.schema.SchemaEngine.Columns
6+
import troy.schema.SchemaEngine.{ Asterisk, Columns }
77

88
object SchemaTestUtils extends FlatSpec with Matchers {
99
def buildSchema(versionedStatements: String*) =
@@ -12,6 +12,9 @@ object SchemaTestUtils extends FlatSpec with Matchers {
1212
def analyse(query: String)(implicit schema: VersionedSchemaEngine) =
1313
schema(parseQuery(query))
1414

15+
def asteriskOf(query: String)(implicit schema: VersionedSchemaEngine) =
16+
analyse(query).get._1.asInstanceOf[Asterisk].types
17+
1518
def columnsOf(query: String)(implicit schema: VersionedSchemaEngine) =
1619
analyse(query).get._1.asInstanceOf[Columns].types
1720

0 commit comments

Comments
 (0)