1616import org .elasticsearch .xpack .esql .parser .ParsingException ;
1717
1818import java .time .ZoneId ;
19+ import java .time .ZoneOffset ;
20+ import java .util .function .Function ;
1921
2022public class QuerySettings {
2123 // TODO check cluster state and see if project routing is allowed
@@ -30,7 +32,8 @@ public class QuerySettings {
3032 "A project routing expression, "
3133 + "used to define which projects to route the query to. "
3234 + "Only supported if Cross-Project Search is enabled." ,
33- (value , settings ) -> Foldables .stringLiteralValueOf (value , "Unexpected value" )
35+ (value , settings ) -> Foldables .stringLiteralValueOf (value , "Unexpected value" ),
36+ (_rcs ) -> null
3437 );
3538
3639 public static final QuerySettingDef <ZoneId > TIME_ZONE = new QuerySettingDef <>(
@@ -47,7 +50,8 @@ public class QuerySettings {
4750 } catch (Exception exc ) {
4851 throw new QlIllegalArgumentException ("Invalid time zone [" + timeZone + "]" );
4952 }
50- }
53+ },
54+ (_rcs ) -> ZoneOffset .UTC
5155 );
5256
5357 public static final QuerySettingDef <?>[] ALL_SETTINGS = { PROJECT_ROUTING , TIME_ZONE };
@@ -86,6 +90,7 @@ public static void validate(EsqlStatement statement, RemoteClusterService cluste
8690 * @param validator A validation function to check the setting value.
8791 * Defaults to calling the {@link #parser} and returning the error message of any exception it throws.
8892 * @param parser A function to parse the setting value into the final object.
93+ * @param defaultValueSupplier A supplier of the default value to be used when the setting is not set.
8994 * @param <T> The type of the setting value.
9095 */
9196 public record QuerySettingDef <T >(
@@ -96,7 +101,8 @@ public record QuerySettingDef<T>(
96101 boolean snapshotOnly ,
97102 String description ,
98103 Validator validator ,
99- Parser <T > parser
104+ Parser <T > parser ,
105+ Function <RemoteClusterService , T > defaultValueSupplier
100106 ) {
101107 public QuerySettingDef (
102108 String name ,
@@ -105,7 +111,8 @@ public QuerySettingDef(
105111 boolean preview ,
106112 boolean snapshotOnly ,
107113 String description ,
108- Parser <T > parser
114+ Parser <T > parser ,
115+ Function <RemoteClusterService , T > defaultValueSupplier
109116 ) {
110117 this (name , type , serverlessOnly , preview , snapshotOnly , description , (value , rcs ) -> {
111118 try {
@@ -114,10 +121,13 @@ public QuerySettingDef(
114121 } catch (Exception exc ) {
115122 return exc .getMessage ();
116123 }
117- }, parser );
124+ }, parser , defaultValueSupplier );
118125 }
119126
120127 public T get (Expression value , RemoteClusterService clusterService ) {
128+ if (value == null ) {
129+ return defaultValueSupplier .apply (clusterService );
130+ }
121131 return parser .parse (value , clusterService );
122132 }
123133
0 commit comments