File tree 2 files changed +9
-43
lines changed
ndc-connector-snowflake/src/main/kotlin/io/hasura/snowflake
ndc-sqlgen/src/main/kotlin/io/hasura/ndc/sqlgen
2 files changed +9
-43
lines changed Original file line number Diff line number Diff line change 1
1
package io.hasura
2
2
3
+ import io.hasura.ndc.common.ConnectorConfiguration
3
4
import io.hasura.ndc.ir.*
4
5
import io.hasura.ndc.ir.extensions.isVariablesRequest
5
6
import io.hasura.ndc.sqlgen.BaseQueryGenerator
@@ -18,9 +19,9 @@ object CTEQueryGenerator : BaseQueryGenerator() {
18
19
override fun queryRequestToSQL (
19
20
request : QueryRequest
20
21
): Select <* > {
21
- return buildCTEs(request)
22
- .select(DSL .jsonArrayAgg(DSL .field(DSL .name(listOf (" data" , ROWS_AND_AGGREGATES )))))
23
- .from(buildSelections(request).asTable(" data" ))
22
+ return buildCTEs(request)
23
+ .select(DSL .jsonArrayAgg(DSL .field(DSL .name(listOf (" data" , ROWS_AND_AGGREGATES )))))
24
+ .from(buildSelections(request).asTable(" data" ))
24
25
}
25
26
26
27
@@ -44,10 +45,11 @@ object CTEQueryGenerator : BaseQueryGenerator() {
44
45
}
45
46
46
47
private fun buildCTEs (request : QueryRequest , varCTE : List <CommonTableExpression <* >> = emptyList()): WithStep {
47
- return DSL .with (
48
- varCTE +
49
- forEachQueryLevelRecursively(request, CTEQueryGenerator ::buildCTE).distinct()
50
- )
48
+ val withStep = mkNativeQueryCTEs(request)
49
+ .with (varCTE)
50
+ .with (forEachQueryLevelRecursively(request, CTEQueryGenerator ::buildCTE).distinct())
51
+
52
+ return withStep
51
53
}
52
54
53
55
private fun getCollectionAsjOOQName (collection : String ): Name {
Original file line number Diff line number Diff line change @@ -128,42 +128,6 @@ abstract class BaseQueryGenerator : BaseGenerator {
128
128
return withStep
129
129
}
130
130
131
- fun mkNativeQueryCTE (
132
- request : QueryRequest
133
- ): org.jooq.WithStep {
134
- val config = ConnectorConfiguration .Loader .config
135
-
136
- fun renderNativeQuerySQL (
137
- nativeQuery : NativeQueryInfo ,
138
- arguments : Map <String , Argument >
139
- ): String {
140
- val sql = nativeQuery.sql
141
- val parts = sql.parts
142
-
143
- return parts.joinToString(" " ) { part ->
144
- when (part) {
145
- is NativeQueryPart .Text -> part.value
146
- is NativeQueryPart .Parameter -> {
147
- val argument = arguments[part.value] ? : error(" Argument ${part.value} not found" )
148
- when (argument) {
149
- is Argument .Literal -> argument.value.toString()
150
- else -> error(" Only literals are supported in Native Queries in this version" )
151
- }
152
- }
153
- }
154
- }
155
- }
156
-
157
- val nativeQuery = config.nativeQueries[request.collection]!!
158
- val nativeQuerySQL = renderNativeQuerySQL(nativeQuery, request.arguments)
159
-
160
- return DSL .with (
161
- DSL .name(request.collection)
162
- ).`as `(
163
- DSL .resultQuery(nativeQuerySQL)
164
- )
165
- }
166
-
167
131
fun getQueryColumnFields (fields : Map <String , IRField >): Map <String , IRField .ColumnField > {
168
132
return fields
169
133
.filterValues { it is IRField .ColumnField }
You can’t perform that action at this time.
0 commit comments