apache / apache/pulsar

[Bug] When the Schema structure is incorrect, SQL queries return Not a record: "string"

Open
#20,945 1 comment 1 reaction 1 assignee Claimed by @crossoverJie View on GitHub
Stale type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Version

master

### Minimal reproduce step

## Create producer
`Producer p = pulsarClient.newProducer(Schema.JSON(String.class)).create()`

It would generate the following schema:

```json
{
"version": 0,
"schemaInfo": {
"name": "schema-test-2",
"schema": "\"string\"",
"type": "JSON",
"timestamp": 1691379461556,
"properties": {
"__alwaysAllowNull": "true",
"__jsr310ConversionEnabled": "false"
}
}
}
```

And query from `Trino`:
```sql
select * from pulsar."public/default"."schema-test-2";
```
![image](https://github.com/apache/pulsar/assets/15684156/94dcf40e-7741-4b89-9123-c052b5b13f16)

`Trino` service did not report any exception.
![image](https://github.com/apache/pulsar/assets/15684156/16229a9e-6f86-42b0-a0fb-9fd0d04787f8)

### What did you expect to see?

Query success.

### What did you see instead?

Query 20230807_075157_00000_b7hfa failed: Not a record: "string"

### Anything else?

This exception was thrown from there:

https://github.com/apache/pulsar/blob/2ab184e49a036a1dd10dc537bef4ab034a5ad5e0/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericSchemaImpl.java#L43-L46

Because there are a large amount of these types of codes in our production environment, we hope that they can be compatible in this situation in the `pulsar-sql` module.

When parsing the Schema encounters exceptions, use defaultSchema to regenerate, like this:

![image](https://github.com/apache/pulsar/assets/15684156/565c4e73-ef43-46b3-afbe-d41989e194fb)

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.