@@ -9,7 +9,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
99 // Positive Tests (Should Compile)
1010 // ============================================================
1111
12- " SQLQueryValidator" should " validate all numeric types" in {
12+ " SQLQueryValidator" should " VALIDATE all numeric types" in {
1313 assertCompiles("""
1414 import app.softnetwork.elastic.client.macros.TestElasticClientApi
1515 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -21,7 +21,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
2121 )""" )
2222 }
2323
24- it should " validate string types" in {
24+ it should " VALIDATE string types" in {
2525 assertCompiles("""
2626 import app.softnetwork.elastic.client.macros.TestElasticClientApi
2727 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -33,7 +33,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
3333 )""" )
3434 }
3535
36- it should " validate temporal types" in {
36+ it should " VALIDATE temporal types" in {
3737 assertCompiles("""
3838 import app.softnetwork.elastic.client.macros.TestElasticClientApi
3939 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -45,7 +45,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
4545 )""" )
4646 }
4747
48- it should " validate Product with all fields" in {
48+ it should " VALIDATE with all fields" in {
4949 assertCompiles("""
5050 import app.softnetwork.elastic.client.macros.TestElasticClientApi
5151 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -57,7 +57,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
5757 )""" )
5858 }
5959
60- it should " validate with aliases" in {
60+ it should " VALIDATE with aliases" in {
6161 assertCompiles("""
6262 import app.softnetwork.elastic.client.macros.TestElasticClientApi
6363 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -69,7 +69,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
6969 )""" )
7070 }
7171
72- it should " accept query with missing Option fields" in {
72+ it should " ACCEPT query with missing Option fields" in {
7373 assertCompiles("""
7474 import app.softnetwork.elastic.client.macros.TestElasticClientApi
7575 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -82,7 +82,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
8282 """ )
8383 }
8484
85- it should " accept query with missing fields that have defaults" in {
85+ it should " ACCEPT query with missing fields that have defaults" in {
8686 assertCompiles("""
8787 import app.softnetwork.elastic.client.macros.TestElasticClientApi
8888 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -95,7 +95,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
9595 """ )
9696 }
9797
98- it should " accept SELECT * with Unchecked variant" in {
98+ it should " ACCEPT SELECT * with Unchecked variant" in {
9999 assertCompiles("""
100100 import app.softnetwork.elastic.client.macros.TestElasticClientApi
101101 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -108,6 +108,28 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
108108 """ )
109109 }
110110
111+ it should " ACCEPT nested object with complete selection" in {
112+ assertCompiles("""
113+ import app.softnetwork.elastic.client.macros.TestElasticClientApi
114+ import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
115+ import app.softnetwork.elastic.sql.macros.SQLQueryValidatorSpec.{User, Address}
116+
117+ TestElasticClientApi.searchAs[User](
118+ "SELECT id, name, address FROM users"
119+ )""" )
120+ }
121+
122+ it should " ACCEPT nested object with UNNEST" in {
123+ assertCompiles("""
124+ import app.softnetwork.elastic.client.macros.TestElasticClientApi
125+ import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
126+ import app.softnetwork.elastic.sql.macros.SQLQueryValidatorSpec.{User, Address}
127+
128+ TestElasticClientApi.searchAs[User](
129+ "SELECT id, name, address.street, address.city, address.country FROM users JOIN UNNEST(users.address) AS address"
130+ )""" )
131+ }
132+
111133 // ============================================================
112134 // Negative Tests (Should NOT Compile)
113135 // ============================================================
@@ -149,7 +171,7 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
149171 )""" )
150172 }
151173
152- it should " suggest closest field names" in {
174+ it should " SUGGEST closest field names" in {
153175 assertDoesNotCompile("""
154176 import app.softnetwork.elastic.client.macros.TestElasticClientApi
155177 import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
@@ -200,6 +222,17 @@ class SQLQueryValidatorSpec extends AnyFlatSpec with Matchers {
200222 """ )
201223 }
202224
225+ it should " REJECT nested object with individual field selection without UNNEST" in {
226+ assertDoesNotCompile("""
227+ import app.softnetwork.elastic.client.macros.TestElasticClientApi
228+ import app.softnetwork.elastic.client.macros.TestElasticClientApi.defaultFormats
229+ import app.softnetwork.elastic.sql.macros.SQLQueryValidatorSpec.{User, Address}
230+
231+ TestElasticClientApi.searchAs[User](
232+ "SELECT id, name, address.street, address.city, address.country FROM users"
233+ )""" )
234+ }
235+
203236}
204237
205238object SQLQueryValidatorSpec {
@@ -249,4 +282,16 @@ object SQLQueryValidatorSpec {
249282 dt : java.time.LocalDateTime ,
250283 ts : java.time.Instant
251284 )
285+
286+ case class Address (
287+ street : String ,
288+ city : String ,
289+ country : String
290+ )
291+
292+ case class User (
293+ id : String ,
294+ name : String ,
295+ address : Address
296+ )
252297}
0 commit comments