Best way to create a new type

Hi everyone !

I’m looking for a way to create a new type in a plugin with two parameters…something like

MY_TYPE( ‘test’, 123)

what is the best way to do it and, will it be recognize in a SQL line like

CREATE TABLE table as (c MY_TYPE( ‘test’, 123) ) ??

Thanks !

Check out this commit when they added JSON type in 2014. Some stuff has likely changed, but honestly, I doubt too much. This would also require adding the type to SQL in the ANTLR definition in the trino-parser. This was the commit where JSON was added but the file has changed a lot since then.

Let me know if there are follow up questions. Unfortunately there’s not a guide we can officially point to for these types of changes yet.

Thanks Brian!

That was part of the first thing I made (working my way through AntlR, etc…) but I found it pretty bad as I was changing to many things in the core package.

What I managed to do is:

  • creating a parametric type
  • register my new type using the type signature class.

It was way easier (no change in the core) and way more flexible as I can register as many new type as I want using the parametric type.

Now, my new problem is getting it to the parquet and orc writers! I’m still learning a good way to use the Block class in order to serde my objects…!

Thanks again for pointing me out this commit! It was a good start!

1 Like

Happy to have attempted to help. Although I didn’t feel like I helped too much :smiley: