opensearch-project / opensearch-project/sql

[BUG] Implicit cast to timestamp does not work on text filed

Open
#2,437 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug SQL
Dominant language
Java
Stars
176
Forks
229
Avg merge
2d 21h
Merged PRs (30d)
43

Description

What is the bug?

  • Implicit cast to timestamp does not work for Text field.
select textDate from index where timestamp(textDate) >= \"2023-11-22 23:39:00.000\"
  • log
onException[compare expected value have same type, but with [org.opensearch.sql.opensearch.data.type.OpenSearchTextType@512e772, TIMESTAMP]]; }
        at org.opensearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:687)
        at org.opensearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:376)
        at org.opensearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:726)
        at org.opensearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:495)
        at org.opensearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:298)
        at org.opensearch.action.search.SearchExecutionStatsCollector.onFailure(SearchExecutionStatsCollector.java:104)
        at org.opensearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:74)
        at org.opensearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:755)
        at org.opensearch.transport.TransportService$6.handleException(TransportService.java:884)
        at org.opensearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1504)
        at org.opensearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1618)
        at org.opensearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1592) 
        at org.opensearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:79)
        at org.opensearch.transport.TransportChannel.sendErrorResponse(TransportChannel.java:71)
        at org.opensearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:70)
        at org.opensearch.action.ActionRunnable.onFailure(ActionRunnable.java:103)
        at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:54)
        at org.opensearch.threadpool.TaskAwareRunnable.doRun(TaskAwareRunnable.java:78)
        at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
        at org.opensearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:59)
        at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
        at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: NotSerializableExceptionWrapper[expression_evaluation_exception: compare expected value have same type, but with [org.opensearch.sql.opensearch.data.type.OpenSearchTextType@6c396a95, TIMESTAMP]] 
        at org.opensearch.sql.data.model.AbstractExprValue.compareTo(AbstractExprValue.java:30)
        at org.opensearch.sql.data.model.AbstractExprValue.compareTo(AbstractExprValue.java:14)
        at org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperator.lambda$gte$95048fc1$1(BinaryPredicateOperator.java:203)
        at org.opensearch.sql.expression.function.FunctionDSL.lambda$nullMissingHandling$a5005281$1(FunctionDSL.java:412)
        at org.opensearch.sql.expression.function.FunctionDSL.lambda$impl$a0fb34d4$1(FunctionDSL.java:285)
        at org.opensearch.sql.expression.function.FunctionDSL$3.valueOf(FunctionDSL.java:166)
        at org.opensearch.sql.opensearch.storage.script.filter.ExpressionFilterScript.evaluateExpression(ExpressionFilterScript.java:48)
        at org.opensearch.sql.opensearch.storage.script.core.ExpressionScript.lambda$execute$2(ExpressionScript.java:85)
        at java.security.AccessController.doPrivileged(AccessController.java:318)
        at org.opensearch.sql.opensearch.storage.script.core.ExpressionScript.execute(ExpressionScript.java:82)
        at org.opensearch.sql.opensearch.storage.script.filter.ExpressionFilterScript.execute(ExpressionFilterScript.java:43)
        at org.opensearch.index.query.ScriptQueryBuilder$ScriptQuery$1$1.matches(ScriptQueryBuilder.java:226)
        at org.apache.lucene.search.ConjunctionDISI$ConjunctionTwoPhaseIterator.matches(ConjunctionDISI.java:346)
        at org.apache.lucene.search.Weight$DefaultBulkScorer.scoreRange(Weight.java:281)
        at org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:254)
        at org.opensearch.search.internal.CancellableBulkScorer.score(CancellableBulkScorer.java:71)
        at org.apache.lucene.search.BulkScorer.score(BulkScorer.java:38)
        at org.opensearch.search.internal.ContextIndexSearcher.searchLeaf(ContextIndexSearcher.java:316)
        at org.opensearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:276)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:551)
        at org.opensearch.search.query.QueryPhase.searchWithCollector(QueryPhase.java:360)
        at org.opensearch.search.query.QueryPhase$DefaultQueryPhaseSearcher.searchWithCollector(QueryPhase.java:447)
        at org.opensearch.search.query.QueryPhase$DefaultQueryPhaseSearcher.searchWith(QueryPhase.java:431)
        at org.opensearch.search.query.QueryPhaseSearcherWrapper.searchWith(QueryPhaseSearcherWrapper.java:64)
        at org.opensearch.search.query.QueryPhase.executeInternal(QueryPhase.java:282)
        at org.opensearch.search.query.QueryPhase.execute(QueryPhase.java:155)
        at org.opensearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:532)
        at org.opensearch.search.SearchService.executeQueryPhase(SearchService.java:596)
        at org.opensearch.search.SearchService$2.lambda$onResponse$0(SearchService.java:565)
        at org.opensearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:73)
        at org.opensearch.action.ActionRunnable$2.doRun(ActionRunnable.java:88)
        at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
        at org.opensearch.threadpool.TaskAwareRunnable.doRun(TaskAwareRunnable.java:78)
        at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
        at org.opensearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:59)
        at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:917)
        at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.lang.Thread.run(Thread.java:833)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractExprValue.compareTo and BinaryPredicateOperator.gte in the stack trace, then trace how timestamp(textDate) is evaluated through the expression functions. Reproduce the shown query and verify that comparing the cast text field with the timestamp no longer raises a type-mismatch error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.