Skip to content

Commit b666d5a

Browse files
authored
Update WvcLib.scala
1 parent 43a5ec2 commit b666d5a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

_patches/WvcLib.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,21 @@ object WvcLib extends LogSupport:
3232
*/
3333
@exported("wvlet_compile_query")
3434
def compile_query(queryJson: CString): CString =
35-
stackalloc[CChar]((1024)).asInstanceOf[CString]
35+
try
36+
val json = fromCString(queryJson)
37+
val query = MessageCodec.of[String].fromJson(json)
38+
val args = Array("-q", query, "-x")
39+
val (sql, _) = WvcMain.compileWvletQuery(args)
40+
41+
val buffer = stackalloc[CChar](sql.length + 1)
42+
var i = 0
43+
while (i < sql.length) {
44+
buffer(i) = sql.charAt(i).toByte
45+
i += 1
46+
}
47+
buffer(sql.length) = 0.toByte
48+
buffer.asInstanceOf[CString]
49+
catch
50+
case e: Throwable =>
51+
warn(e)
52+
stackalloc[CChar](1).asInstanceOf[CString]

0 commit comments

Comments
 (0)