Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLFrame: On the "all-types" validation, use char instead of character #767

Open
wants to merge 1 commit into
base: sqlframe
Choose a base branch
from

Conversation

amotl
Copy link
Member

@amotl amotl commented Dec 9, 2024

Introduction

When submitting a record like this to CrateDB using SQLFrame,

# The record that is inserted into the database.
RECORD_IN = dict(
null_integer=None,
integer=42,
bigint=42,
float=42.42,
double=42.42,
decimal=42.42,
bit="01010101",
bool=True,
text="foobar",
character="foo",
timestamp_tz="1970-01-02T00:00:00+01:00",
timestamp_notz="1970-01-02T00:00:00",
ip="127.0.0.1",
array=["foo", "bar"],
object={"foo": "bar"},
geopoint=[85.43, 66.23],
geoshape="POLYGON ((5 5, 10 5, 10 10, 5 10, 5 5))",
float_vector=[1.0, 2.0, 3.0],
)

... it generates SQL statements like this:

SELECT 
  ...
  "integer" AS "integer", 
  "bigint" AS "bigint",
  "float" AS "float", 
  ...

Problem

With an aliasing to char, changed within this patch (instead of character), CrateDB only trips on the "char" AS "char" fragment, but not on others.

psycopg2.errors.InternalError_: line 1:229: no viable alternative at input
SELECT 
  "bool" AS "bool", 
  "text" AS "text", 
  "char" AS'

Most basic reproduction

cr> select 42 as "string";
+---------+
| string |
+---------+
|      42 |
+---------+
SELECT 1 row in set (0.002 sec)
cr> select 42 as "char";
SQLParseException[line 1:14: no viable alternative at input 'select 42 as "char"']

Traceback

FAILED test.py::test_ddl_dml_dql - psycopg2.errors.InternalError_: line 1:229: no viable alternative at input 'SELECT "null_integer", "integer" AS "integer", "bigint" AS "bigint", "float" AS "float", "double" AS "double", "decimal" AS "decimal", "bit" AS "bit", "bool" AS "bool", "text" AS "text", "char" AS'
CONTEXT:  io.crate.exceptions.SQLExceptions.esToCrateException(SQLExceptions.java:211)
io.crate.exceptions.SQLExceptions.prepareForClientTransmission(SQLExceptions.java:200)
io.crate.protocols.postgres.Messages.sendErrorResponse(Messages.java:195)
io.crate.protocols.postgres.Messages.sendErrorResponse(Messages.java:188)
io.crate.protocols.postgres.PostgresWireProtocol.handleSimpleQuery(PostgresWireProtocol.java:800)
io.crate.protocols.postgres.PostgresWireProtocol$MessageHandler.dispatchMessage(PostgresWireProtocol.java:341)
io.crate.protocols.postgres.PostgresWireProtocol$MessageHandler.dispatchState(PostgresWireProtocol.java:331)
io.crate.protocols.postgres.PostgresWireProtocol$MessageHandler.channelRead0(PostgresWireProtocol.java:299)
io.crate.protocols.postgres.PostgresWireProtocol$MessageHandler.channelRead0(PostgresWireProtocol.java:283)
io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
io.crate.protocols.postgres.PgDecoder.channelRead(PgDecoder.java:116)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)

-- https://github.com/crate/cratedb-examples/actions/runs/12234558808/job/34124004513?pr=767#step:6:193

References

With an aliasing to `char`, the response is:

cr> select char as "char" from t01;
SQLParseException[line 1:16: no viable alternative at input 'select char as "char"']

It apparently works with all other symbol names, it just trips on
`char`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant