55
66package org .opensearch .sql .spark .flint ;
77
8- import static org .opensearch .sql .spark .dispatcher .model .FlintIndexOptions .AUTO_REFRESH ;
9- import static org .opensearch .sql .spark .dispatcher .model .FlintIndexOptions .CHECKPOINT_LOCATION ;
10- import static org .opensearch .sql .spark .dispatcher .model .FlintIndexOptions .INCREMENTAL_REFRESH ;
11- import static org .opensearch .sql .spark .dispatcher .model .FlintIndexOptions .WATERMARK_DELAY ;
128import static org .opensearch .sql .spark .flint .FlintIndexMetadata .APP_ID ;
139import static org .opensearch .sql .spark .flint .FlintIndexMetadata .ENV_KEY ;
1410import static org .opensearch .sql .spark .flint .FlintIndexMetadata .KIND_KEY ;
2016import static org .opensearch .sql .spark .flint .FlintIndexMetadata .SERVERLESS_EMR_JOB_ID ;
2117import static org .opensearch .sql .spark .flint .FlintIndexMetadata .SOURCE_KEY ;
2218
23- import java .util .ArrayList ;
24- import java .util .Arrays ;
2519import java .util .HashMap ;
26- import java .util .LinkedHashSet ;
27- import java .util .List ;
2820import java .util .Map ;
29- import java .util .Set ;
3021import lombok .AllArgsConstructor ;
31- import org .apache .commons .lang3 .StringUtils ;
3222import org .apache .logging .log4j .LogManager ;
3323import org .apache .logging .log4j .Logger ;
3424import org .opensearch .action .admin .indices .mapping .get .GetMappingsResponse ;
@@ -43,11 +33,6 @@ public class FlintIndexMetadataServiceImpl implements FlintIndexMetadataService
4333 private static final Logger LOGGER = LogManager .getLogger (FlintIndexMetadataServiceImpl .class );
4434
4535 private final Client client ;
46- public static final Set <String > ALTER_TO_FULL_REFRESH_ALLOWED_OPTIONS =
47- new LinkedHashSet <>(Arrays .asList (AUTO_REFRESH , INCREMENTAL_REFRESH ));
48- public static final Set <String > ALTER_TO_INCREMENTAL_REFRESH_ALLOWED_OPTIONS =
49- new LinkedHashSet <>(
50- Arrays .asList (AUTO_REFRESH , INCREMENTAL_REFRESH , WATERMARK_DELAY , CHECKPOINT_LOCATION ));
5136
5237 @ Override
5338 public Map <String , FlintIndexMetadata > getFlintIndexMetadata (
@@ -87,63 +72,11 @@ public void updateIndexToManualRefresh(
8772 String kind = (String ) meta .get ("kind" );
8873 Map <String , Object > options = (Map <String , Object >) meta .get ("options" );
8974 Map <String , String > newOptions = flintIndexOptions .getProvidedOptions ();
90- validateFlintIndexOptions (kind , options , newOptions );
75+ FlintIndexMetadataValidator . validateFlintIndexOptions (kind , options , newOptions );
9176 options .putAll (newOptions );
9277 client .admin ().indices ().preparePutMapping (indexName ).setSource (flintMetadataMap ).get ();
9378 }
9479
95- private void validateFlintIndexOptions (
96- String kind , Map <String , Object > existingOptions , Map <String , String > newOptions ) {
97- if ((newOptions .containsKey (INCREMENTAL_REFRESH )
98- && Boolean .parseBoolean (newOptions .get (INCREMENTAL_REFRESH )))
99- || ((!newOptions .containsKey (INCREMENTAL_REFRESH )
100- && Boolean .parseBoolean ((String ) existingOptions .get (INCREMENTAL_REFRESH ))))) {
101- validateConversionToIncrementalRefresh (kind , existingOptions , newOptions );
102- } else {
103- validateConversionToFullRefresh (newOptions );
104- }
105- }
106-
107- private void validateConversionToFullRefresh (Map <String , String > newOptions ) {
108- if (!ALTER_TO_FULL_REFRESH_ALLOWED_OPTIONS .containsAll (newOptions .keySet ())) {
109- throw new IllegalArgumentException (
110- String .format (
111- "Altering to full refresh only allows: %s options" ,
112- ALTER_TO_FULL_REFRESH_ALLOWED_OPTIONS ));
113- }
114- }
115-
116- private void validateConversionToIncrementalRefresh (
117- String kind , Map <String , Object > existingOptions , Map <String , String > newOptions ) {
118- if (!ALTER_TO_INCREMENTAL_REFRESH_ALLOWED_OPTIONS .containsAll (newOptions .keySet ())) {
119- throw new IllegalArgumentException (
120- String .format (
121- "Altering to incremental refresh only allows: %s options" ,
122- ALTER_TO_INCREMENTAL_REFRESH_ALLOWED_OPTIONS ));
123- }
124- HashMap <String , Object > mergedOptions = new HashMap <>();
125- mergedOptions .putAll (existingOptions );
126- mergedOptions .putAll (newOptions );
127- List <String > missingAttributes = new ArrayList <>();
128- if (!mergedOptions .containsKey (CHECKPOINT_LOCATION )
129- || StringUtils .isEmpty ((String ) mergedOptions .get (CHECKPOINT_LOCATION ))) {
130- missingAttributes .add (CHECKPOINT_LOCATION );
131- }
132- if (kind .equals ("mv" )
133- && (!mergedOptions .containsKey (WATERMARK_DELAY )
134- || StringUtils .isEmpty ((String ) mergedOptions .get (WATERMARK_DELAY )))) {
135- missingAttributes .add (WATERMARK_DELAY );
136- }
137- if (missingAttributes .size () > 0 ) {
138- String errorMessage =
139- "Conversion to incremental refresh index cannot proceed due to missing attributes: "
140- + String .join (", " , missingAttributes )
141- + "." ;
142- LOGGER .error (errorMessage );
143- throw new IllegalArgumentException (errorMessage );
144- }
145- }
146-
14780 private FlintIndexMetadata fromMetadata (String indexName , Map <String , Object > metaMap ) {
14881 FlintIndexMetadata .FlintIndexMetadataBuilder flintIndexMetadataBuilder =
14982 FlintIndexMetadata .builder ();
0 commit comments