admin 管理员组

文章数量: 1086019

I am finding an error when trying to do a CASE over a byte column. To check this out, you can create a simple table like this:

CREATE TABLE 'byteTest' ( 
    ts TIMESTAMP,
    id SYMBOL CAPACITY 256 CACHE,
    status BYTE
) timestamp(ts) PARTITION BY DAY;

And then execute this query, even without any data inside:

SELECT
  id,
  CASE
      WHEN status = 1 THEN 'ACTIVE'
  END as status
FROM
  byteTest;

The web console returns exception in function factory, and if I check the logs I can see the following output:

2025-03-27T12:21:40.032872Z E i.q.g.FunctionParser exception in function factory:
java.lang.UnsupportedOperationException
    at io.questdb.griffin.engine.functions.IntFunction.getByte(IntFunction.java:55)
    at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.getByte(SwitchFunctionFactory.java:174)
    at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.getIntKeyedFunction(SwitchFunctionFactory.java:420)
    at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.newInstance(SwitchFunctionFactory.java:136)
    at io.questdb.griffin.FunctionParser.checkAndCreateFunction(FunctionParser.java:566)
    at io.questdb.griffin.FunctionParser.createFunction(FunctionParser.java:1001)
    at io.questdb.griffin.FunctionParser.visit(FunctionParser.java:391)
    at io.questdb.griffin.PostOrderTreeTraversalAlgo.traverse(PostOrderTreeTraversalAlgo.java:96)
    at io.questdb.griffin.FunctionParser.parseFunction(FunctionParser.java:319)
    at io.questdb.griffin.SqlCodeGenerator.generateSelectVirtualWithSubQuery(SqlCodeGenerator.java:4449)
    at io.questdb.griffin.SqlCodeGenerator.generateSelectVirtual(SqlCodeGenerator.java:4422)
    at io.questdb.griffin.SqlCodeGenerator.generateSelect(SqlCodeGenerator.java:3733)
    at io.questdb.griffin.SqlCodeGenerator.generateQuery0(SqlCodeGenerator.java:3282)
    at io.questdb.griffin.SqlCodeGenerator.generateQuery(SqlCodeGenerator.java:3270)
    at io.questdb.griffin.SqlCodeGenerator.generate(SqlCodeGenerator.java:529)
    at io.questdb.griffin.SqlCompilerImpl.generateSelectOneShot(SqlCompilerImpl.java:3714)
    at io.questdb.griffin.SqlCompilerImpl.generateSelectWithRetries(SqlCompilerImpl.java:422)
    at io.questdb.griffin.SqlCompilerImplpileUsingModel(SqlCompilerImpl.java:2244)
    at io.questdb.griffin.SqlCompilerImplpileInner(SqlCompilerImpl.java:1928)
    at io.questdb.griffin.SqlCompilerImplpile(SqlCompilerImpl.java:305)
    at io.questdb.cairo.pool.SqlCompilerPool$Cpile(SqlCompilerPool.java:138)
    at io.questdb.cutlass.http.processors.JsonQueryProcessorpileAndExecuteQuery(JsonQueryProcessor.java:542)
    at io.questdb.cutlass.http.processors.JsonQueryProcessor.execute0(JsonQueryProcessor.java:224)
    at io.questdb.cutlass.http.processors.JsonQueryProcessor.onRequestComplete(JsonQueryProcessor.java:296)
    at io.questdb.cutlass.http.HttpConnectionContext.handleClientRecv(HttpConnectionContext.java:991)
    at io.questdb.cutlass.http.HttpConnectionContext.handleClientOperation(HttpConnectionContext.java:307)
    at io.questdb.cutlass.http.HttpServer.handleClientOperation(HttpServer.java:345)
    at io.questdb.cutlass.http.HttpServer$1.lambda$$0(HttpServer.java:129)
    at io.questdbwork.AbstractIODispatcher.processIOQueue(AbstractIODispatcher.java:216)
    at io.questdb.cutlass.http.HttpServer$1.run(HttpServer.java:133)
    at io.questdb.mp.Worker.run(Worker.java:152)

2025-03-27T12:21:40.033831Z E i.q.g.e.QueryProgress err [id=-1, sql=`SELECT
  id,
  CASE
      WHEN status = 1 THEN 'ACTIVE'
  END as status
FROM
  byteTest`, principal=admin, cache=false, jit=true, time=10207500, msg=exception in function factory: , errno=0, pos=15]
2025-03-27T12:21:44.866629Z I http-server disconnected [ip=127.0.0.1, fd=154619049490, src=queue]

Not sure what I am doing wrong here.

I am finding an error when trying to do a CASE over a byte column. To check this out, you can create a simple table like this:

CREATE TABLE 'byteTest' ( 
    ts TIMESTAMP,
    id SYMBOL CAPACITY 256 CACHE,
    status BYTE
) timestamp(ts) PARTITION BY DAY;

And then execute this query, even without any data inside:

SELECT
  id,
  CASE
      WHEN status = 1 THEN 'ACTIVE'
  END as status
FROM
  byteTest;

The web console returns exception in function factory, and if I check the logs I can see the following output:

2025-03-27T12:21:40.032872Z E i.q.g.FunctionParser exception in function factory:
java.lang.UnsupportedOperationException
    at io.questdb.griffin.engine.functions.IntFunction.getByte(IntFunction.java:55)
    at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.getByte(SwitchFunctionFactory.java:174)
    at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.getIntKeyedFunction(SwitchFunctionFactory.java:420)
    at io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory.newInstance(SwitchFunctionFactory.java:136)
    at io.questdb.griffin.FunctionParser.checkAndCreateFunction(FunctionParser.java:566)
    at io.questdb.griffin.FunctionParser.createFunction(FunctionParser.java:1001)
    at io.questdb.griffin.FunctionParser.visit(FunctionParser.java:391)
    at io.questdb.griffin.PostOrderTreeTraversalAlgo.traverse(PostOrderTreeTraversalAlgo.java:96)
    at io.questdb.griffin.FunctionParser.parseFunction(FunctionParser.java:319)
    at io.questdb.griffin.SqlCodeGenerator.generateSelectVirtualWithSubQuery(SqlCodeGenerator.java:4449)
    at io.questdb.griffin.SqlCodeGenerator.generateSelectVirtual(SqlCodeGenerator.java:4422)
    at io.questdb.griffin.SqlCodeGenerator.generateSelect(SqlCodeGenerator.java:3733)
    at io.questdb.griffin.SqlCodeGenerator.generateQuery0(SqlCodeGenerator.java:3282)
    at io.questdb.griffin.SqlCodeGenerator.generateQuery(SqlCodeGenerator.java:3270)
    at io.questdb.griffin.SqlCodeGenerator.generate(SqlCodeGenerator.java:529)
    at io.questdb.griffin.SqlCompilerImpl.generateSelectOneShot(SqlCompilerImpl.java:3714)
    at io.questdb.griffin.SqlCompilerImpl.generateSelectWithRetries(SqlCompilerImpl.java:422)
    at io.questdb.griffin.SqlCompilerImplpileUsingModel(SqlCompilerImpl.java:2244)
    at io.questdb.griffin.SqlCompilerImplpileInner(SqlCompilerImpl.java:1928)
    at io.questdb.griffin.SqlCompilerImplpile(SqlCompilerImpl.java:305)
    at io.questdb.cairo.pool.SqlCompilerPool$Cpile(SqlCompilerPool.java:138)
    at io.questdb.cutlass.http.processors.JsonQueryProcessorpileAndExecuteQuery(JsonQueryProcessor.java:542)
    at io.questdb.cutlass.http.processors.JsonQueryProcessor.execute0(JsonQueryProcessor.java:224)
    at io.questdb.cutlass.http.processors.JsonQueryProcessor.onRequestComplete(JsonQueryProcessor.java:296)
    at io.questdb.cutlass.http.HttpConnectionContext.handleClientRecv(HttpConnectionContext.java:991)
    at io.questdb.cutlass.http.HttpConnectionContext.handleClientOperation(HttpConnectionContext.java:307)
    at io.questdb.cutlass.http.HttpServer.handleClientOperation(HttpServer.java:345)
    at io.questdb.cutlass.http.HttpServer$1.lambda$$0(HttpServer.java:129)
    at io.questdbwork.AbstractIODispatcher.processIOQueue(AbstractIODispatcher.java:216)
    at io.questdb.cutlass.http.HttpServer$1.run(HttpServer.java:133)
    at io.questdb.mp.Worker.run(Worker.java:152)

2025-03-27T12:21:40.033831Z E i.q.g.e.QueryProgress err [id=-1, sql=`SELECT
  id,
  CASE
      WHEN status = 1 THEN 'ACTIVE'
  END as status
FROM
  byteTest`, principal=admin, cache=false, jit=true, time=10207500, msg=exception in function factory: , errno=0, pos=15]
2025-03-27T12:21:44.866629Z I http-server disconnected [ip=127.0.0.1, fd=154619049490, src=queue]

Not sure what I am doing wrong here.

Share Improve this question asked Mar 27 at 12:27 Javier RamirezJavier Ramirez 4,0851 gold badge27 silver badges36 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In this case, this is a QuestDB bug. It has been already reported on GitHub, and there has been some work on the issue, which according to one of the engineers should be fixed soon.

In the meantime, the simple workaround is casting the byte to an integer instead

SELECT
  id,
  CASE
      WHEN status::int = 1 THEN 'ACTIVE'
  END as status
FROM
  byteTest;

本文标签: databaseException in function factory with a CASE statementStack Overflow