-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add JSON
__getitem__
operation
- Loading branch information
Showing
19 changed files
with
179 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from pathlib import Path | ||
from typing import Any | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Tests for JSON operations.""" | ||
|
||
import pandas as pd | ||
import pytest | ||
from pytest import param | ||
|
||
|
||
@pytest.mark.notimpl(["datafusion", "pyspark"]) | ||
@pytest.mark.notyet(["clickhouse"], reason="upstream is broken") | ||
@pytest.mark.never(["impala"], reason="doesn't support JSON and never will") | ||
@pytest.mark.parametrize( | ||
("expr_fn", "expected"), | ||
[ | ||
param( | ||
lambda t: t.js["a"].name("res"), | ||
pd.Series( | ||
[[1, 2, 3, 4], None, "foo", None, None, None], | ||
name="res", | ||
dtype="object", | ||
), | ||
id="getitem_object", | ||
marks=[pytest.mark.min_server_version(sqlite="3.38.0")], | ||
), | ||
param( | ||
lambda t: t.js[1].name("res"), | ||
pd.Series( | ||
[None, None, None, None, 47, None], | ||
dtype="object", | ||
name="res", | ||
), | ||
marks=[pytest.mark.min_server_version(sqlite="3.38.0")], | ||
id="getitem_array", | ||
), | ||
], | ||
) | ||
def test_json_getitem(backend, json_t, expr_fn, expected): | ||
expr = expr_fn(json_t) | ||
result = expr.execute() | ||
backend.assert_series_equal(result, expected) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from public import public | ||
|
||
import ibis.expr.datatypes as dt | ||
import ibis.expr.rules as rlz | ||
from ibis.expr.operations import Value | ||
|
||
|
||
@public | ||
class JSONGetItem(Value): | ||
arg = rlz.json | ||
|
||
index = rlz.one_of((rlz.string, rlz.integer)) | ||
|
||
output_dtype = dt.json | ||
output_shape = rlz.shape_like("args") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
from public import public | ||
|
||
from ibis.expr.types.binary import BinaryColumn, BinaryScalar, BinaryValue | ||
from ibis.expr.types.strings import StringColumn, StringScalar, StringValue | ||
from ibis.expr.types import Column, Scalar, Value | ||
|
||
|
||
@public | ||
class JSONValue(StringValue): | ||
pass # noqa: E701,E302 | ||
class JSONValue(Value): | ||
def __getitem__(self, key): | ||
import ibis.expr.operations as ops | ||
|
||
return ops.JSONGetItem(self, key).to_expr() | ||
|
||
|
||
@public | ||
class JSONScalar(StringScalar, JSONValue): | ||
class JSONScalar(Scalar, JSONValue): | ||
pass # noqa: E701,E302 | ||
|
||
|
||
@public | ||
class JSONColumn(StringColumn, JSONValue): | ||
class JSONColumn(Column, JSONValue): | ||
pass # noqa: E701,E302 | ||
|
||
|
||
@public | ||
class JSONBValue(BinaryValue): | ||
class JSONBValue(Value): | ||
pass # noqa: E701,E302 | ||
|
||
|
||
@public | ||
class JSONBScalar(BinaryScalar, JSONBValue): | ||
class JSONBScalar(Scalar, JSONBValue): | ||
pass # noqa: E701,E302 | ||
|
||
|
||
@public | ||
class JSONBColumn(BinaryColumn, JSONBValue): | ||
class JSONBColumn(Column, JSONBValue): | ||
pass # noqa: E701,E302 |