1919import com .fasterxml .jackson .databind .SerializerProvider ;
2020import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
2121import com .fasterxml .jackson .databind .ser .std .StdSerializer ;
22+ import com .google .common .collect .ImmutableList ;
2223import com .google .common .collect .ImmutableMap ;
2324import com .google .common .collect .ImmutableSet ;
2425import io .airlift .compress .zstd .ZstdDecompressor ;
2930import io .trino .sql .parser .SqlParser ;
3031import io .trino .sql .tree .AddColumn ;
3132import io .trino .sql .tree .Analyze ;
33+ import io .trino .sql .tree .Call ;
34+ import io .trino .sql .tree .CallArgument ;
3235import io .trino .sql .tree .CreateCatalog ;
3336import io .trino .sql .tree .CreateMaterializedView ;
3437import io .trino .sql .tree .CreateSchema ;
@@ -85,6 +88,7 @@ public class TrinoQueryProperties
8588{
8689 private final Logger log = Logger .get (TrinoQueryProperties .class );
8790 private final boolean isClientsUseV2Format ;
91+ private final int maxBodySize ;
8892 private String body = "" ;
8993 private String queryType = "" ;
9094 private String resourceGroupQueryType = "" ;
@@ -94,6 +98,8 @@ public class TrinoQueryProperties
9498 private Set <String > catalogs = ImmutableSet .of ();
9599 private Set <String > schemas = ImmutableSet .of ();
96100 private Set <String > catalogSchemas = ImmutableSet .of ();
101+ private Optional <Call > procedure = Optional .empty ();
102+ private List <CallArgument > procedureArguments = ImmutableList .of ();
97103 private boolean isNewQuerySubmission ;
98104 private boolean isQueryParsingSuccessful ;
99105
@@ -127,21 +133,28 @@ public TrinoQueryProperties(
127133 this .isNewQuerySubmission = isNewQuerySubmission ;
128134 this .isQueryParsingSuccessful = isQueryParsingSuccessful ;
129135 isClientsUseV2Format = false ;
136+ maxBodySize = -1 ;
130137 }
131138
132139 public TrinoQueryProperties (HttpServletRequest request , RequestAnalyzerConfig config )
133140 {
134- isClientsUseV2Format = config .isClientsUseV2Format ();
141+ this (request , config .isClientsUseV2Format (), config .getMaxBodySize ());
142+ }
143+
144+ public TrinoQueryProperties (HttpServletRequest request , boolean isClientsUseV2Format , int maxBodySize )
145+ {
146+ this .isClientsUseV2Format = isClientsUseV2Format ;
147+ this .maxBodySize = maxBodySize ;
135148
136149 defaultCatalog = Optional .ofNullable (request .getHeader (TRINO_CATALOG_HEADER_NAME ));
137150 defaultSchema = Optional .ofNullable (request .getHeader (TRINO_SCHEMA_HEADER_NAME ));
138151 if (request .getMethod ().equals (HttpMethod .POST )) {
139152 isNewQuerySubmission = true ;
140- processRequestBody (request , config );
153+ processRequestBody (request );
141154 }
142155 }
143156
144- private void processRequestBody (HttpServletRequest request , RequestAnalyzerConfig config )
157+ private void processRequestBody (HttpServletRequest request )
145158 {
146159 try (BufferedReader reader = request .getReader ()) {
147160 if (reader == null ) {
@@ -152,11 +165,11 @@ private void processRequestBody(HttpServletRequest request, RequestAnalyzerConfi
152165
153166 Map <String , String > preparedStatements = getPreparedStatements (request );
154167 SqlParser parser = new SqlParser ();
155- reader .mark (config . getMaxBodySize () );
156- char [] buffer = new char [config . getMaxBodySize () ];
157- int nChars = reader .read (buffer , 0 , config . getMaxBodySize () );
168+ reader .mark (maxBodySize );
169+ char [] buffer = new char [maxBodySize ];
170+ int nChars = reader .read (buffer , 0 , maxBodySize );
158171 reader .reset ();
159- if (nChars == config . getMaxBodySize () ) {
172+ if (nChars == maxBodySize ) {
160173 log .warn ("Query length greater or equal to requestAnalyzerConfig.maxBodySize detected" );
161174 return ;
162175 //The body is truncated - there is a chance that it could still be syntactically valid SQL, for example if truncated on
@@ -194,7 +207,7 @@ private void processRequestBody(HttpServletRequest request, RequestAnalyzerConfi
194207 ImmutableSet .Builder <String > schemaBuilder = ImmutableSet .builder ();
195208 ImmutableSet .Builder <String > catalogSchemaBuilder = ImmutableSet .builder ();
196209
197- getNames (statement , tableBuilder , catalogBuilder , schemaBuilder , catalogSchemaBuilder );
210+ visitNode (statement , tableBuilder , catalogBuilder , schemaBuilder , catalogSchemaBuilder );
198211 tables = tableBuilder .build ();
199212 catalogBuilder .addAll (tables .stream ().map (q -> q .getParts ().getFirst ()).iterator ());
200213 catalogs = catalogBuilder .build ();
@@ -256,7 +269,7 @@ private String decodePreparedStatementFromHeader(String headerValue)
256269 return new String (preparedStatement , UTF_8 );
257270 }
258271
259- private void getNames (Node node , ImmutableSet .Builder <QualifiedName > tableBuilder ,
272+ private void visitNode (Node node , ImmutableSet .Builder <QualifiedName > tableBuilder ,
260273 ImmutableSet .Builder <String > catalogBuilder ,
261274 ImmutableSet .Builder <String > schemaBuilder ,
262275 ImmutableSet .Builder <String > catalogSchemaBuilder )
@@ -265,6 +278,11 @@ private void getNames(Node node, ImmutableSet.Builder<QualifiedName> tableBuilde
265278 switch (node ) {
266279 case AddColumn s -> tableBuilder .add (qualifyName (s .getName ()));
267280 case Analyze s -> tableBuilder .add (qualifyName (s .getTableName ()));
281+ case Call call -> {
282+ procedure = Optional .of (call );
283+ procedureArguments = call .getArguments ();
284+ return ;
285+ }
268286 case CreateCatalog s -> catalogBuilder .add (s .getCatalogName ().getValue ());
269287 case CreateMaterializedView s -> tableBuilder .add (qualifyName (s .getName ()));
270288 case CreateSchema s -> setCatalogAndSchemaNameFromSchemaQualifiedName (Optional .of (s .getSchemaName ()), catalogBuilder , schemaBuilder , catalogSchemaBuilder );
@@ -338,7 +356,7 @@ private void getNames(Node node, ImmutableSet.Builder<QualifiedName> tableBuilde
338356 }
339357
340358 for (Node child : node .getChildren ()) {
341- getNames (child , tableBuilder , catalogBuilder , schemaBuilder , catalogSchemaBuilder );
359+ visitNode (child , tableBuilder , catalogBuilder , schemaBuilder , catalogSchemaBuilder );
342360 }
343361 }
344362
@@ -513,6 +531,16 @@ public boolean isQueryParsingSuccessful()
513531 return isQueryParsingSuccessful ;
514532 }
515533
534+ public Optional <Call > getProcedure ()
535+ {
536+ return procedure ;
537+ }
538+
539+ public List <CallArgument > getProcedureArguments ()
540+ {
541+ return procedureArguments ;
542+ }
543+
516544 public static class AlternateStatementRequestBodyFormat
517545 {
518546 // Based on https://github.com/trinodb/trino/wiki/trino-v2-client-protocol, without session
0 commit comments