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.
Add OpenSearchTable in flint core (opensearch-project#479)
Signed-off-by: Peng Huo <[email protected]>
- Loading branch information
Showing
32 changed files
with
831 additions
and
462 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
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
15 changes: 15 additions & 0 deletions
15
flint-core/src/main/scala/org/opensearch/flint/core/JsonSchema.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,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core | ||
|
||
/** | ||
* Schema in OpenSearch index mapping format. | ||
* | ||
* @param jsonSchema | ||
*/ | ||
case class JsonSchema(jsonSchema: String) extends Schema { | ||
override def asJson(): String = jsonSchema | ||
} |
28 changes: 28 additions & 0 deletions
28
flint-core/src/main/scala/org/opensearch/flint/core/MetaData.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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core | ||
|
||
import org.opensearch.flint.core.metadata.FlintMetadata | ||
|
||
/** | ||
* OpenSearch Table metadata. | ||
* | ||
* @param name | ||
* name | ||
* @param properties | ||
* properties | ||
* @param setting | ||
* setting | ||
*/ | ||
case class MetaData(name: String, properties: String, setting: String) | ||
|
||
object MetaData { | ||
def apply(name: String, flintMetadata: FlintMetadata): MetaData = { | ||
val properties = flintMetadata.getContent | ||
val setting = flintMetadata.indexSettings.getOrElse("") | ||
MetaData(name, properties, setting) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
flint-core/src/main/scala/org/opensearch/flint/core/Schema.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,20 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core | ||
|
||
/** | ||
* Table Schema. | ||
*/ | ||
trait Schema { | ||
|
||
/** | ||
* Return table schema as Json. | ||
* | ||
* @return | ||
* schema. | ||
*/ | ||
def asJson(): String | ||
} |
85 changes: 85 additions & 0 deletions
85
flint-core/src/main/scala/org/opensearch/flint/core/Table.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,85 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core | ||
|
||
import java.io.IOException | ||
import java.util | ||
|
||
import com.google.common.base.Strings | ||
import org.opensearch.common.settings.Settings | ||
import org.opensearch.common.xcontent.{NamedXContentRegistry, XContentType} | ||
import org.opensearch.common.xcontent.DeprecationHandler.IGNORE_DEPRECATIONS | ||
import org.opensearch.flint.core.storage.FlintReader | ||
import org.opensearch.index.query.{AbstractQueryBuilder, MatchAllQueryBuilder, QueryBuilder} | ||
import org.opensearch.plugins.SearchPlugin | ||
import org.opensearch.search.SearchModule | ||
|
||
/** | ||
* A OpenSearch Table. | ||
*/ | ||
trait Table extends Serializable { | ||
|
||
/** | ||
* OpenSearch Table MetaData. | ||
* | ||
* @return | ||
* {@link Table} | ||
*/ | ||
def metaData(): MetaData | ||
|
||
/** | ||
* Is OpenSearch Table splittable. | ||
* | ||
* @return | ||
* true if splittable, otherwise false. | ||
*/ | ||
def isSplittable(): Boolean = false | ||
|
||
/** | ||
* Slice OpenSearch Table. | ||
* @return | ||
* a sequence of sliced OpenSearch Table | ||
*/ | ||
def slice(): Seq[Table] | ||
|
||
/** | ||
* Create Flint Reader from DSL query. | ||
* | ||
* @param query | ||
* OpenSearch DSL query. | ||
* @return | ||
*/ | ||
def createReader(query: String): FlintReader | ||
|
||
/** | ||
* OpenSearch Table schema | ||
* | ||
* @return | ||
* {@link Schema} | ||
*/ | ||
def schema(): Schema | ||
} | ||
|
||
object Table { | ||
|
||
/** | ||
* {@link NamedXContentRegistry} from {@link SearchModule} used for construct {@link | ||
* QueryBuilder} from DSL query string. | ||
*/ | ||
val xContentRegistry = new NamedXContentRegistry( | ||
new SearchModule(Settings.builder.build, new util.ArrayList[SearchPlugin]).getNamedXContents) | ||
|
||
@throws[IOException] | ||
def queryBuilder(query: String): QueryBuilder = { | ||
if (!Strings.isNullOrEmpty(query)) { | ||
val parser = | ||
XContentType.JSON.xContent.createParser(xContentRegistry, IGNORE_DEPRECATIONS, query) | ||
AbstractQueryBuilder.parseInnerQueryBuilder(parser) | ||
} else { | ||
new MatchAllQueryBuilder | ||
} | ||
} | ||
} |
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.