Skip to content

Commit 1d1002a

Browse files
committed
to fix table without alias
1 parent 9e684e4 commit 1d1002a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

es6/sql-bridge/src/test/scala/app/softnetwork/elastic/sql/SQLQuerySpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3436,7 +3436,7 @@ class SQLQuerySpec extends AnyFlatSpec with Matchers {
34363436
| "aggs": {
34373437
| "avg_popularity": {
34383438
| "avg": {
3439-
| "field": "blogs.popularity"
3439+
| "field": "popularity"
34403440
| }
34413441
| },
34423442
| "nested_comments": {

sql/bridge/src/test/scala/app/softnetwork/elastic/sql/SQLQuerySpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3436,7 +3436,7 @@ class SQLQuerySpec extends AnyFlatSpec with Matchers {
34363436
| "aggs": {
34373437
| "avg_popularity": {
34383438
| "avg": {
3439-
| "field": "blogs.popularity"
3439+
| "field": "popularity"
34403440
| }
34413441
| },
34423442
| "nested_comments": {

sql/src/main/scala/app/softnetwork/elastic/sql/query/From.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ case class From(tables: Seq[Table]) extends Updateable {
148148
.flatten
149149

150150
lazy val tableAliases: Map[String, String] = tables
151-
.flatMap((table: Table) => table.tableAlias.map(alias => table.name -> alias.alias))
151+
.flatMap((table: Table) =>
152+
table.tableAlias match {
153+
case Some(alias) if alias.alias.nonEmpty => Some(table.name -> alias.alias)
154+
case _ => Some(table.name -> table.name)
155+
}
156+
)
152157
.toMap ++ unnestAliases.map(unnest => unnest._2._1 -> unnest._1)
153158

154159
lazy val unnestAliases: Map[String, (String, Option[Limit])] = unnests

0 commit comments

Comments
 (0)