Add python binding for ZOrderCoveringIndexConfig (#519)

This commit is contained in:
EJ Song 2022-01-04 14:49:32 -08:00 коммит произвёл GitHub
Родитель 1adddf6d54
Коммит db4bef41b1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 50 добавлений и 6 удалений

Просмотреть файл

@ -1,6 +1,6 @@
from .hyperspace import Hyperspace
from .indexconfig import CoveringIndexConfig, IndexConfig
from .indexconfig import CoveringIndexConfig, ZOrderCoveringIndexConfig, IndexConfig
__all__ = [
'Hyperspace', 'CoveringIndexConfig', 'IndexConfig'
'Hyperspace', 'CoveringIndexConfig', 'ZOrderCoveringIndexConfig', 'IndexConfig'
]

Просмотреть файл

@ -21,9 +21,9 @@ class Hyperspace:
def _getJavaCoveringIndexConfig(self, index_config):
"""
Constructs CoveringIndexConfig Java object from python wrapper CoveringIndexConfig object.
:param index_config: CoveringIndexConfig java object
:return: CoveringIndexConfig python object
Constructs CoveringIndexConfig Java object from python wrapper object.
:param index_config: CoveringIndexConfig python object
:return: CoveringIndexConfig java object
>>> _getJavaCoveringIndexConfig(idx_config)
"""
@ -33,6 +33,21 @@ class Hyperspace:
self.jvm.java.lang.String(index_config.indexName), indexed_columns, included_columns)
return _jindexConfig
def _getJavaZOrderCoveringIndexConfig(self, index_config):
"""
Constructs ZOrderCoveringIndexConfig Java object from python wrapper object.
:param index_config: ZOrderCoveringIndexConfig python object
:return: ZOrderCoveringIndexConfig java object
>>> _getJavaZOrderCoveringIndexConfig(idx_config)
"""
indexed_columns = self._getScalaSeqFromList(index_config.indexedColumns)
included_columns = self._getScalaSeqFromList(index_config.includedColumns)
index_name = self.jvm.java.lang.String(index_config.indexName)
_jZOrderIndexConfig = self.jvm.com.microsoft.hyperspace.index.zordercovering. \
ZOrderCoveringIndexConfig(index_name, indexed_columns, included_columns)
return _jZOrderIndexConfig
def _getScalaSeqFromList(self, list):
"""
Constructs scala sequence from Java's List object.
@ -71,7 +86,14 @@ class Hyperspace:
>>> df = spark.read.parquet("./sample.parquet").toDF("c1", "c2", "c3")
>>> hyperspace.createIndex(df, indexConfig)
"""
self.hyperspace.createIndex(dataFrame._jdf, self._getJavaCoveringIndexConfig(indexConfig))
if isinstance(indexConfig, CoveringIndexConfig):
self.hyperspace.createIndex(dataFrame._jdf, \
self._getJavaCoveringIndexConfig(indexConfig))
elif isinstance(indexConfig, ZOrderCoveringIndexConfig):
self.hyperspace.createIndex(dataFrame._jdf, \
self._getJavaZOrderCoveringIndexConfig(indexConfig))
else:
raise Exception("Invalid index config type: " + type(indexConfig).__name__)
def deleteIndex(self, indexName):
"""

Просмотреть файл

@ -13,4 +13,19 @@ class CoveringIndexConfig:
self.indexedColumns = indexedColumns
self.includedColumns = includedColumns
class ZOrderCoveringIndexConfig:
def __init__(self, indexName, indexedColumns, includedColumns):
"""
Initializes ZOrderCoveringIndexConfig object.
:param indexName: index name
:param indexedColumns: indexed columns
:param includedColumns: included columns
:return: ZOrderCoveringIndexConfig object
>>> idxConfig = ZOrderCoveringIndexConfig("indexName", ["c1"], ["c2","c3"])
"""
self.indexName = indexName
self.indexedColumns = indexedColumns
self.includedColumns = includedColumns
IndexConfig = CoveringIndexConfig

Просмотреть файл

@ -34,6 +34,13 @@ class HyperspaceIndexManagementTests(HyperspaceTestCase):
self.hyperspace.createIndex(self.df, idx_config)
self.assertEqual(self.hyperspace.indexes().filter("""name = "idx1" """).count(), 1)
def test_index_create_zorder(self):
idx_config = ZOrderCoveringIndexConfig('zidx1', ['name'], ['age'])
self.hyperspace.createIndex(self.df, idx_config)
self.assertEqual(self.hyperspace.indexes().filter("""name = "zidx1" """).count(), 1)
self.assertEqual(self.hyperspace.index("zidx1"). \
filter("""kind = "ZOrderCoveringIndex" """).count(), 1)
def test_index_delete(self):
idx_config = IndexConfig('idx2', ['name'], ['age'])
self.hyperspace.createIndex(self.df, idx_config)