forked from opensearch-project/opensearch-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract service for accessing Flint index metadata (opensearch-proje…
…ct#495) * fix missed renames * rename for log entry properties * correct typo planTransformer Signed-off-by: Sean Kao <[email protected]> * add FlintIndexMetadataService * interface class for FlintIndexMetadataService * move FlintMetadata and FlintVersion to flint-commons * remove ser/de from FlintMetadata; move to OS impl for FlintIndexMetadataService * remove schema parser in FlintMetadata builder to remove dependency to opensearch * FlintSparkIndex generate not only schema json but also map * FlintMetadataSuite divided into two: one for builder and one for ser/de, which is merged to FlintOpenSearchIndexMetadataServiceSuite Signed-off-by: Sean Kao <[email protected]> * move get metadata functions to new service * Remove getIndexMetadata and getAllIndexMetadata from FlintClient * Implement the two for OpenSearch * TODO: sanitize index name * Add builder for FlintIndexMetadataService and options * Refactor caller of FlintClient.get(All)IndexMetadata with FlintIndexMetadataService * TODO: test suite for getIndexMetadata and getAllIndexMetadata (might overlap with FlintOpenSearchClientSuite) Signed-off-by: Sean Kao <[email protected]> * update index metadata * remove updateIndex from FlintClient * implement updateIndexMetadata for FlintOpenSearchIndexMetadataService * updateIndexMetadata upon create index in FlintSpark * for OS client + OS index metadata service, the call for update is redundant * it's for when some other index metadata service implementation is provided * TODO: Suite for updateIndexMetadata (now shared with FlintOpenSearchClientSuite) Signed-off-by: Sean Kao <[email protected]> * empty implementation for OS deleteIndexMetadata Signed-off-by: Sean Kao <[email protected]> * sanitize index name Signed-off-by: Sean Kao <[email protected]> * fix new FlintOption missing from FlintSparkConf Signed-off-by: Sean Kao <[email protected]> * fix FlintOpenSearchClientSuite Signed-off-by: Sean Kao <[email protected]> * delete file (missed in resolving conflict) Signed-off-by: Sean Kao <[email protected]> * Use service builder in OpenSearchCluster Signed-off-by: Sean Kao <[email protected]> * fix service builder class * fix FlintOptions for custom class spark properties * remove SparkConf from builder argument Signed-off-by: Sean Kao <[email protected]> * fix IT Signed-off-by: Sean Kao <[email protected]> * add test suites Signed-off-by: Sean Kao <[email protected]> * sanitize index name for opensearch metadata log Signed-off-by: Sean Kao <[email protected]> * remove spark-warehouse files Signed-off-by: Sean Kao <[email protected]> * exclude _meta field for createIndex in OpenSearch Signed-off-by: Sean Kao <[email protected]> * catch client creation exception Signed-off-by: Sean Kao <[email protected]> * Fetch metadata for OpenSearch table * OpenSearchCluster move to java file because scala object cannot be mocked in mockito Signed-off-by: Sean Kao <[email protected]> * update doc with spark config Signed-off-by: Sean Kao <[email protected]> --------- Signed-off-by: Sean Kao <[email protected]>
- Loading branch information
1 parent
15ee355
commit f5ad574
Showing
41 changed files
with
815 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ommons/src/main/scala/org/opensearch/flint/common/metadata/FlintIndexMetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.common.metadata; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Flint index metadata service provides API for index metadata related operations on a Flint index | ||
* regardless of underlying storage. | ||
* <p> | ||
* Custom implementations of this interface are expected to provide a public constructor with | ||
* the signature {@code public MyCustomService(SparkConf sparkConf)} to be instantiated by | ||
* the FlintIndexMetadataServiceBuilder. | ||
*/ | ||
public interface FlintIndexMetadataService { | ||
|
||
/** | ||
* Retrieve metadata for a Flint index. | ||
* | ||
* @param indexName index name | ||
* @return index metadata | ||
*/ | ||
FlintMetadata getIndexMetadata(String indexName); | ||
|
||
/** | ||
* Retrieve all metadata for Flint index whose name matches the given pattern. | ||
* | ||
* @param indexNamePattern index name pattern | ||
* @return map where the keys are the matched index names, and the values are | ||
* corresponding index metadata | ||
*/ | ||
Map<String, FlintMetadata> getAllIndexMetadata(String... indexNamePattern); | ||
|
||
/** | ||
* Update metadata for a Flint index. | ||
* | ||
* @param indexName index name | ||
* @param metadata index metadata to update | ||
*/ | ||
void updateIndexMetadata(String indexName, FlintMetadata metadata); | ||
|
||
/** | ||
* Delete metadata for a Flint index. | ||
* | ||
* @param indexName index name | ||
*/ | ||
void deleteIndexMetadata(String indexName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
flint-commons/src/test/scala/org/opensearch/flint/common/metadata/FlintMetadataSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.common.metadata | ||
|
||
import scala.collection.JavaConverters.mapAsJavaMapConverter | ||
|
||
import org.opensearch.flint.common.FlintVersion.current | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class FlintMetadataSuite extends AnyFlatSpec with Matchers { | ||
"builder" should "build FlintMetadata with provided fields" in { | ||
val builder = new FlintMetadata.Builder | ||
builder.name("test_index") | ||
builder.kind("test_kind") | ||
builder.source("test_source_table") | ||
builder.addIndexedColumn(Map[String, AnyRef]("test_field" -> "spark_type").asJava) | ||
builder.schema(Map[String, AnyRef]("test_field" -> Map("type" -> "os_type").asJava).asJava) | ||
|
||
val metadata = builder.build() | ||
|
||
metadata.version shouldBe current() | ||
metadata.name shouldBe "test_index" | ||
metadata.kind shouldBe "test_kind" | ||
metadata.source shouldBe "test_source_table" | ||
metadata.indexedColumns shouldBe Array(Map("test_field" -> "spark_type").asJava) | ||
metadata.schema shouldBe Map("test_field" -> Map("type" -> "os_type").asJava).asJava | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.