Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new object dataTypes and write tests for them #570

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/docker-compose-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- 8081:8081
restart: on-failure:0
Expand Down
4 changes: 2 additions & 2 deletions ci/docker-compose-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: '3.4'
services:
weaviate-node-1:
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
restart: on-failure:0
ports:
- "8087:8080"
Expand All @@ -25,7 +25,7 @@ services:
- '8080'
- --scheme
- http
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- 8088:8080
- 6061:6060
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose-okta-cc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- 8082:8082
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose-okta-users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- 8083:8083
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose-openai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- '8086'
- --scheme
- http
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- 8086:8086
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose-wcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- 8085:8085
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:preview-make-proto-naming-consistent-4b98dfa
image: semitechnologies/weaviate:preview-nested-objects-4dc2c30
ports:
- "8080:8080"
- "50051:50051"
Expand Down
33 changes: 33 additions & 0 deletions integration/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,36 @@ def test_add_ref_batch_with_tenant():

for name in reversed(class_names):
client.schema.delete_class(name)


def test_add_nested_object_with_batch():
client = weaviate.Client("http://localhost:8080")
client.schema.delete_all()

client.schema.create_class(
{
"class": "BatchTestNested",
"vectorizer": "none",
"properties": [
{
"name": "nested",
"dataType": ["object"],
"nestedProperties": [
{"name": "name", "dataType": ["text"]},
{"name": "names", "dataType": ["text[]"]},
],
}
],
},
)

uuid_ = uuid.uuid4()
with client.batch as batch:
batch.add_data_object(
class_name="BatchTestNested",
data_object={"nested": {"name": "nested", "names": ["nested1", "nested2"]}},
uuid=uuid_,
)

obj = client.data_object.get_by_id(uuid_, class_name="BatchTestNested")
assert obj["properties"]["nested"] == {"name": "nested", "names": ["nested1", "nested2"]}
4 changes: 2 additions & 2 deletions integration/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import weaviate

GIT_HASH = "4b98dfa"
SERVER_VERSION = "1.21.3"
GIT_HASH = "4dc2c30"
SERVER_VERSION = "1.21.4"
NODE_NAME = "node1"
NUM_OBJECT = 10

Expand Down
113 changes: 113 additions & 0 deletions integration/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,116 @@ def test_tenants():
tenant=tenants[i].name,
)
assert not exists


@pytest.mark.parametrize(
"prop_defs,props",
[
(
{
"dataType": ["text"],
"name": "name",
},
{
"name": "test",
},
),
(
{
"dataType": ["text[]"],
"name": "names",
},
{
"names": ["test1", "test2"],
},
),
(
{
"dataType": ["int"],
"name": "age",
},
{
"age": 42,
},
),
(
{
"dataType": ["int[]"],
"name": "ages",
},
{
"ages": [42, 43],
},
),
(
{
"dataType": ["number"],
"name": "height",
},
{
"height": 1.80,
},
),
(
{
"dataType": ["number[]"],
"name": "heights",
},
{
"heights": [1.00, 1.80],
},
),
(
{
"dataType": ["boolean"],
"name": "isTall",
},
{
"isTall": True,
},
),
(
{
"dataType": ["boolean[]"],
"name": "areTall",
},
{
"areTall": [False, True],
},
),
(
{
"dataType": ["date"],
"name": "birthday",
},
{
"birthday": "2021-01-01T00:00:00Z",
},
),
(
{
"dataType": ["date[]"],
"name": "birthdays",
},
{
"birthdays": ["2021-01-01T00:00:00Z", "2021-01-02T00:00:00Z"],
},
),
],
)
def test_nested_object_datatype(prop_defs: dict, props: dict):
client = weaviate.Client("http://localhost:8080")
client.schema.delete_all()
client.schema.create_class(
{
"class": "A",
"properties": [
{"name": "nested", "dataType": ["object"], "nestedProperties": [prop_defs]},
],
"vectorizer": "none",
}
)

uuid_ = client.data_object.create({"nested": props}, "A")
obj = client.data_object.get_by_id(uuid_, class_name="A")
assert obj["properties"]["nested"] == props
92 changes: 92 additions & 0 deletions integration/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,95 @@ def test_graphql_with_tenant():
int(results["data"]["Aggregate"][schema_class["class"]][0]["meta"]["count"])
== nr_objects // 2
)


def test_graphql_with_nested_object():
client = weaviate.Client("http://localhost:8080")
client.schema.delete_all()
client.schema.create_class(
{
"class": "NestedObjectClass",
"vectorizer": "none",
"properties": [
{
"name": "nested",
"dataType": ["object"],
"nestedProperties": [
{
"name": "name",
"dataType": ["text"],
},
{
"name": "names",
"dataType": ["text[]"],
},
{
"name": "age",
"dataType": ["int"],
},
{
"name": "ages",
"dataType": ["int[]"],
},
{
"name": "weight",
"dataType": ["number"],
},
{
"name": "weights",
"dataType": ["number[]"],
},
{
"name": "isAlive",
"dataType": ["boolean"],
},
{
"name": "areAlive",
"dataType": ["boolean[]"],
},
{
"name": "date",
"dataType": ["date"],
},
{
"name": "dates",
"dataType": ["date[]"],
},
{
"name": "uuid",
"dataType": ["uuid"],
},
{
"name": "uuids",
"dataType": ["uuid[]"],
},
],
}
],
}
)
data = {
"name": "nested object",
"names": ["nested", "object"],
"age": 42,
"ages": [42, 43],
"weight": 42.42,
"weights": [42.42, 43.43],
"isAlive": True,
"areAlive": [True, False],
"date": "2021-01-01T00:00:00Z",
"dates": ["2021-01-01T00:00:00Z", "2021-01-02T00:00:00Z"],
"uuid": "00000000-0000-0000-0000-000000000000",
"uuids": ["00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000001"],
}
uuid_ = client.data_object.create({"nested": data}, "NestedObjectClass")

results = client.query.get(
"NestedObjectClass",
[
"nested { name names age ages weight weights isAlive areAlive date dates uuid uuids } _additional { id }"
],
).do()
print(results)
assert results["data"]["Get"]["NestedObjectClass"][0]["nested"] == data
assert results["data"]["Get"]["NestedObjectClass"][0]["_additional"]["id"] == uuid_
49 changes: 47 additions & 2 deletions integration/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_create_class_with_implicit_and_explicit_replication_factor(


@pytest.mark.parametrize("data_type", ["uuid", "uuid[]"])
def test_uuid_datatype(client, data_type):
def test_uuid_datatype(client: weaviate.Client, data_type: str):
single_class = {"class": "UuidTest", "properties": [{"dataType": [data_type], "name": "heat"}]}

client.schema.create_class(single_class)
Expand All @@ -56,8 +56,53 @@ def test_uuid_datatype(client, data_type):
client.schema.delete_class("UuidTest")


@pytest.mark.parametrize("object_", ["object", "object[]"])
@pytest.mark.parametrize(
"nested",
[
{
"dataType": ["text"],
"name": "name",
},
{"dataType": ["text[]"], "name": "names"},
{"dataType": ["int"], "name": "age"},
{"dataType": ["int[]"], "name": "ages"},
{"dataType": ["number"], "name": "weight"},
{"dataType": ["number[]"], "name": "weights"},
{"dataType": ["boolean"], "name": "isAlive"},
{"dataType": ["boolean[]"], "name": "areAlive"},
{"dataType": ["date"], "name": "birthDate"},
{"dataType": ["date[]"], "name": "birthDates"},
{"dataType": ["uuid"], "name": "uuid"},
{"dataType": ["uuid[]"], "name": "uuids"},
{"dataType": ["blob"], "name": "blob"},
{
"dataType": ["object"],
"name": "object",
"nestedProperties": [{"dataType": ["text"], "name": "name"}],
},
{
"dataType": ["object[]"],
"name": "objects",
"nestedProperties": [{"dataType": ["text"], "name": "name"}],
},
],
)
def test_object_datatype(client: weaviate.Client, object_: str, nested: dict):
single_class = {
"class": "ObjectTest",
"properties": [{"dataType": [object_], "name": "heat", "nestedProperties": [nested]}],
}

client.schema.create_class(single_class)
created_class = client.schema.get("ObjectTest")
assert created_class["class"] == "ObjectTest"

client.schema.delete_class("ObjectTest")


@pytest.mark.parametrize("tokenization", ["word", "whitespace", "lowercase", "field"])
def test_tokenization(client, tokenization):
def test_tokenization(client: weaviate.Client, tokenization):
single_class = {
"class": "TokenTest",
"properties": [{"dataType": ["text"], "name": "heat", "tokenization": tokenization}],
Expand Down
Loading