From 8f30173555c496cdc7aecb2a563c8a0d9679b43d Mon Sep 17 00:00:00 2001 From: "xiaolei.zl@alibaba-inc.com" Date: Fri, 10 Jan 2025 11:49:48 +0800 Subject: [PATCH 1/5] add discriminator field for GSDataType Committed-by: xiaolei.zl@alibaba-inc.com from Dev container --- .../sdk/examples/python/basic_example.py | 12 ++-- flex/openapi/openapi_interactive.yaml | 64 ++++++++++++------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/flex/interactive/sdk/examples/python/basic_example.py b/flex/interactive/sdk/examples/python/basic_example.py index f53209a77600..d77bfbe90c24 100644 --- a/flex/interactive/sdk/examples/python/basic_example.py +++ b/flex/interactive/sdk/examples/python/basic_example.py @@ -19,6 +19,10 @@ import os import time + +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), "../../python/")) + from gs_interactive.client.driver import Driver from gs_interactive.client.session import Session from gs_interactive.models import * @@ -38,15 +42,15 @@ "properties": [ { "property_name": "id", - "property_type": {"primitive_type": "DT_SIGNED_INT64"}, + "property_type": {"type_name": "PrimitiveType", "primitive_type": "DT_SIGNED_INT64"}, }, { "property_name": "name", - "property_type": {"string": {"long_text": ""}}, + "property_type": {"type_name": "StringType", "string": {"long_text": ""}}, }, { "property_name": "age", - "property_type": {"primitive_type": "DT_SIGNED_INT32"}, + "property_type": {"type_name": "TimeStampType", "primitive_type": "DT_SIGNED_INT32"}, }, ], "primary_keys": ["id"], @@ -65,7 +69,7 @@ "properties": [ { "property_name": "weight", - "property_type": {"primitive_type": "DT_DOUBLE"}, + "property_type": {"type_name": "PrimitiveType","primitive_type": "DT_DOUBLE"}, } ], "primary_keys": [], diff --git a/flex/openapi/openapi_interactive.yaml b/flex/openapi/openapi_interactive.yaml index bdbf4474907b..853d92d91f7b 100644 --- a/flex/openapi/openapi_interactive.yaml +++ b/flex/openapi/openapi_interactive.yaml @@ -1320,16 +1320,18 @@ components: $ref: '#/components/schemas/AnyValue' PrimitiveType: x-body-name: primitive_type - type: object - required: - - primitive_type - properties: - primitive_type: - type: string - enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64, - DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] - # The DT_STRING is added for backward compatibility, it should be replaced by StringType - example: DT_SIGNED_INT32 + allOf: + - $ref: '#/components/schemas/BaseGSDataType' + - type: object + required: + - primitive_type + properties: + primitive_type: + type: string + enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64, + DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] + # The DT_STRING is added for backward compatibility, it should be replaced by StringType + example: DT_SIGNED_INT32 LongText: x-body-name: long_text type: object @@ -1370,15 +1372,17 @@ components: type: integer StringType: x-body-name: string_type - type: object - required: - - string - properties: - string: - oneOf: - - $ref: '#/components/schemas/LongText' - - $ref: '#/components/schemas/FixedChar' - - $ref: '#/components/schemas/VarChar' + allOf: + - $ref: '#/components/schemas/BaseGSDataType' + - type: object + required: + - string + properties: + string: + oneOf: + - $ref: '#/components/schemas/LongText' + - $ref: '#/components/schemas/FixedChar' + - $ref: '#/components/schemas/VarChar' TimeStampType: x-body-name: time_stamp_type type: object @@ -1397,14 +1401,26 @@ components: type: string TemporalType: x-body-name: temporal_type + allOf: + - $ref: '#/components/schemas/BaseGSDataType' + - type: object + required: + - temporal + properties: + temporal: + oneOf: + - $ref: '#/components/schemas/TimeStampType' + - $ref: '#/components/schemas/DateType' + BaseGSDataType: + x-body-name: base_gs_data_type type: object required: - - temporal + - type_name properties: - temporal: - oneOf: - - $ref: '#/components/schemas/TimeStampType' - - $ref: '#/components/schemas/DateType' + type_name: + type: string + discriminator: + propertyName: type_name GSDataType: x-body-name: gs_data_type oneOf: From 6f55b767637b3d581baf010754821be5bc6f9a1a Mon Sep 17 00:00:00 2001 From: "xiaolei.zl@alibaba-inc.com" Date: Fri, 10 Jan 2025 14:07:33 +0800 Subject: [PATCH 2/5] add base type for other oneof types Committed-by: xiaolei.zl@alibaba-inc.com from Dev container --- flex/openapi/openapi_interactive.yaml | 102 +++++++++++++++++--------- 1 file changed, 66 insertions(+), 36 deletions(-) diff --git a/flex/openapi/openapi_interactive.yaml b/flex/openapi/openapi_interactive.yaml index 853d92d91f7b..4dd9fa4be8b0 100644 --- a/flex/openapi/openapi_interactive.yaml +++ b/flex/openapi/openapi_interactive.yaml @@ -1332,44 +1332,60 @@ components: DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] # The DT_STRING is added for backward compatibility, it should be replaced by StringType example: DT_SIGNED_INT32 - LongText: - x-body-name: long_text + BaseStringType: + x-body-name: base_string_type type: object - additionalProperties: false required: - - long_text + - string_type properties: - long_text: + string_type: type: string - nullable: true + discriminator: + propertyName: string_type + LongText: + x-body-name: long_text + allOf: + - $ref: '#/components/schemas/BaseStringType' + - type: object + additionalProperties: false + required: + - long_text + properties: + long_text: + type: string + nullable: true FixedChar: x-body-name: fixed_char - type: object - additionalProperties: false - required: - - char - properties: - char: - type: object + allOf: + - $ref: '#/components/schemas/BaseStringType' + - type: object + additionalProperties: false required: - - fixed_length + - char properties: - fixed_length: - type: integer + char: + type: object + required: + - fixed_length + properties: + fixed_length: + type: integer VarChar: x-body-name: var_char - type: object - additionalProperties: false - required: - - var_char - properties: - var_char: - type: object + allOf: + - $ref: '#/components/schemas/BaseStringType' + - type: object + additionalProperties: false required: - - max_length + - var_char properties: - max_length: - type: integer + var_char: + type: object + required: + - max_length + properties: + max_length: + type: integer StringType: x-body-name: string_type allOf: @@ -1383,22 +1399,36 @@ components: - $ref: '#/components/schemas/LongText' - $ref: '#/components/schemas/FixedChar' - $ref: '#/components/schemas/VarChar' - TimeStampType: - x-body-name: time_stamp_type + BaseTemporalType: + x-body-name: base_temporal_type type: object required: - - timestamp + - temporal_type properties: - timestamp: + temporal_type: type: string + discriminator: + propertyName: temporal_type + TimeStampType: + x-body-name: time_stamp_type + allOf: + - $ref: '#/components/schemas/BaseTemporalType' + - type: object + required: + - timestamp + properties: + timestamp: + type: string DateType: x-body-name: date_type - type: object - required: - - date32 - properties: - date32: - type: string + allOf: + - $ref: '#/components/schemas/BaseTemporalType' + - type: object + required: + - date32 + properties: + date32: + type: string TemporalType: x-body-name: temporal_type allOf: From 976cc1a136620a8e0c045e2141a43623327200e7 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl@alibaba-inc.com" Date: Mon, 13 Jan 2025 22:34:20 +0800 Subject: [PATCH 3/5] add spring server generator Committed-by: xiaolei.zl@alibaba-inc.com from Dev container --- .gitignore | 11 ++ flex/interactive/sdk/generate_sdk.sh | 18 ++ flex/openapi/openapi_interactive.yaml | 165 +++++++----------- .../groot-http/.openapi-generator-ignore | 31 ++++ interactive_engine/groot-http/README.md | 21 +++ interactive_engine/groot-http/pom.xml | 82 +++++++++ .../deserializer/GSDataTypeDeserializer.java | 46 +++++ .../StringTypeStringDeserializer.java | 53 ++++++ .../TemporalTypeTemporalDeserializer.java | 39 +++++ 9 files changed, 360 insertions(+), 106 deletions(-) create mode 100644 interactive_engine/groot-http/.openapi-generator-ignore create mode 100644 interactive_engine/groot-http/README.md create mode 100644 interactive_engine/groot-http/pom.xml create mode 100644 interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java create mode 100644 interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java create mode 100644 interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java diff --git a/.gitignore b/.gitignore index 64d448025de3..1e8c80ebe761 100644 --- a/.gitignore +++ b/.gitignore @@ -158,6 +158,17 @@ flex/interactive/sdk/python/gs_interactive/rest.py !flex/interactive/sdk/python/gs_interactive/models/long_text.py +interactive_engine/groot-http/.openapi-generator/ +interactive_engine/groot-http/src/test/ +interactive_engine/groot-http/src/main/resources/ +interactive_engine/groot-http/src/main/java/org/ +interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/api/ +interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/ +interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/*.java +!interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java +!interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java +!interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java + **/.cache/ **/*.ci-friendly-pom.xml diff --git a/flex/interactive/sdk/generate_sdk.sh b/flex/interactive/sdk/generate_sdk.sh index e38c33bc9920..776bc21b476f 100755 --- a/flex/interactive/sdk/generate_sdk.sh +++ b/flex/interactive/sdk/generate_sdk.sh @@ -81,6 +81,21 @@ function do_gen_python() { eval $cmd } + +function do_gen_spring() { + echo "Generating Spring API" + OUTPUT_PATH="${CUR_DIR}/../../../interactive_engine/groot-http" + GROOT_PACKAGE_NAME="com.alibaba.graphscope.groot" + GROOT_ARTIFACT_ID="groot-http" + additional_properties="apiPackage=${GROOT_PACKAGE_NAME}.service.api,modelPackage=${GROOT_PACKAGE_NAME}.service.models,artifactId=${GROOT_ARTIFACT_ID},groupId=${GROUP_ID},invokerPackage=${GROOT_PACKAGE_NAME}" + export JAVA_OPTS="-Dlog.level=${LOG_LEVEL}" + cmd="openapi-generator-cli generate -i ${OPENAPI_SPEC_PATH} -g spring -o ${OUTPUT_PATH}" + cmd=" ${cmd} --additional-properties=${additional_properties}" + echo "Running command: ${cmd}" + + eval $cmd +} + function do_gen() { # expect only one argument if [ $# -ne 1 ]; then @@ -97,6 +112,9 @@ function do_gen() { python) do_gen_python ;; + spring) + do_gen_spring + ;; *) err "Unsupported language: $lang" usage diff --git a/flex/openapi/openapi_interactive.yaml b/flex/openapi/openapi_interactive.yaml index 4dd9fa4be8b0..019d2a5552a5 100644 --- a/flex/openapi/openapi_interactive.yaml +++ b/flex/openapi/openapi_interactive.yaml @@ -1320,137 +1320,91 @@ components: $ref: '#/components/schemas/AnyValue' PrimitiveType: x-body-name: primitive_type - allOf: - - $ref: '#/components/schemas/BaseGSDataType' - - type: object - required: - - primitive_type - properties: - primitive_type: - type: string - enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64, - DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] - # The DT_STRING is added for backward compatibility, it should be replaced by StringType - example: DT_SIGNED_INT32 - BaseStringType: - x-body-name: base_string_type type: object - required: - - string_type + required: + - primitive_type properties: - string_type: + primitive_type: type: string - discriminator: - propertyName: string_type + # enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64, + # DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] + # The DT_STRING is added for backward compatibility, it should be replaced by StringType + example: DT_SIGNED_INT32 LongText: x-body-name: long_text - allOf: - - $ref: '#/components/schemas/BaseStringType' - - type: object - additionalProperties: false - required: - - long_text - properties: - long_text: - type: string - nullable: true + type: object + additionalProperties: false + required: + - long_text + properties: + long_text: + type: string + nullable: true FixedChar: x-body-name: fixed_char - allOf: - - $ref: '#/components/schemas/BaseStringType' - - type: object - additionalProperties: false + type: object + additionalProperties: false + required: + - char + properties: + char: + type: object required: - - char + - fixed_length properties: - char: - type: object - required: - - fixed_length - properties: - fixed_length: - type: integer + fixed_length: + type: integer VarChar: x-body-name: var_char - allOf: - - $ref: '#/components/schemas/BaseStringType' - - type: object - additionalProperties: false + type: object + additionalProperties: false + required: + - var_char + properties: + var_char: + type: object required: - - var_char + - max_length properties: - var_char: - type: object - required: - - max_length - properties: - max_length: - type: integer + max_length: + type: integer StringType: x-body-name: string_type - allOf: - - $ref: '#/components/schemas/BaseGSDataType' - - type: object - required: - - string - properties: - string: - oneOf: - - $ref: '#/components/schemas/LongText' - - $ref: '#/components/schemas/FixedChar' - - $ref: '#/components/schemas/VarChar' - BaseTemporalType: - x-body-name: base_temporal_type type: object - required: - - temporal_type + required: + - string properties: - temporal_type: - type: string - discriminator: - propertyName: temporal_type + string: + oneOf: + - $ref: '#/components/schemas/LongText' + - $ref: '#/components/schemas/FixedChar' + - $ref: '#/components/schemas/VarChar' TimeStampType: x-body-name: time_stamp_type - allOf: - - $ref: '#/components/schemas/BaseTemporalType' - - type: object - required: - - timestamp - properties: - timestamp: - type: string + type: object + required: + - timestamp + properties: + timestamp: + type: string DateType: x-body-name: date_type - allOf: - - $ref: '#/components/schemas/BaseTemporalType' - - type: object - required: - - date32 - properties: - date32: - type: string + type: object + required: + - date32 + properties: + date32: + type: string TemporalType: x-body-name: temporal_type - allOf: - - $ref: '#/components/schemas/BaseGSDataType' - - type: object - required: - - temporal - properties: - temporal: - oneOf: - - $ref: '#/components/schemas/TimeStampType' - - $ref: '#/components/schemas/DateType' - BaseGSDataType: - x-body-name: base_gs_data_type type: object required: - - type_name + - temporal properties: - type_name: - type: string - discriminator: - propertyName: type_name + temporal: + oneOf: + - $ref: '#/components/schemas/TimeStampType' + - $ref: '#/components/schemas/DateType' GSDataType: x-body-name: gs_data_type oneOf: @@ -2157,4 +2111,3 @@ components: type: array items: $ref: '#/components/schemas/EdgeRequest' - diff --git a/interactive_engine/groot-http/.openapi-generator-ignore b/interactive_engine/groot-http/.openapi-generator-ignore new file mode 100644 index 000000000000..8d61b64621cd --- /dev/null +++ b/interactive_engine/groot-http/.openapi-generator-ignore @@ -0,0 +1,31 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md + +src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java +src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java +src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java + +README.md + +pom.xml \ No newline at end of file diff --git a/interactive_engine/groot-http/README.md b/interactive_engine/groot-http/README.md new file mode 100644 index 000000000000..5cd22b6081a2 --- /dev/null +++ b/interactive_engine/groot-http/README.md @@ -0,0 +1,21 @@ +# OpenAPI generated server + +Spring Boot Server + +## Overview +This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. +By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub. +This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework. + + +The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org). +Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes. +The specification is available to download using the following url: +http://localhost:8080/v3/api-docs/ + +Start your server as a simple java application + +You can view the api documentation in swagger-ui by pointing to +http://localhost:8080/swagger-ui.html + +Change default port value in application.properties \ No newline at end of file diff --git a/interactive_engine/groot-http/pom.xml b/interactive_engine/groot-http/pom.xml new file mode 100644 index 000000000000..b6040424cea3 --- /dev/null +++ b/interactive_engine/groot-http/pom.xml @@ -0,0 +1,82 @@ + + 4.0.0 + com.alibaba.graphscope + groot-http + jar + groot-http + 1.0.0 + + 1.8 + ${java.version} + ${java.version} + UTF-8 + 1.6.14 + 5.3.1 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + + src/main/java + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.data + spring-data-commons + + + + org.springdoc + springdoc-openapi-ui + ${springdoc.version} + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + org.openapitools + jackson-databind-nullable + 0.2.6 + + + + org.springframework.boot + spring-boot-starter-validation + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java new file mode 100644 index 000000000000..764a60b294ca --- /dev/null +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java @@ -0,0 +1,46 @@ +package com.alibaba.graphscope.groot.service.deserializer; + +import com.alibaba.graphscope.groot.service.models.GSDataType; +import com.alibaba.graphscope.groot.service.models.StringType; +import com.alibaba.graphscope.groot.service.models.PrimitiveType; +import com.alibaba.graphscope.groot.service.models.StringTypeString; +import com.alibaba.graphscope.groot.service.models.TemporalTypeTemporal; +import com.alibaba.graphscope.groot.service.models.TemporalType; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.io.IOException; + + + +public class GSDataTypeDeserializer extends JsonDeserializer { + public GSDataTypeDeserializer() { + } + + @Override + public GSDataType deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode node = jp.getCodec().readTree(jp); + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + System.out.println("GSDataTypeDeserializer"); + System.out.println(node); + + if (node.has("string")) { + StringType stringType = new StringType(); + stringType.setString(mapper.treeToValue(node.get("string"), StringTypeString.class)); + return stringType; + } else if (node.has("temporal")) { + return new TemporalType(jp.getCodec().treeToValue(node.get("temporal"), TemporalTypeTemporal.class)); + } else if (node.has("primitive_type")){ + return new PrimitiveType(jp.getCodec().treeToValue(node.get("primitive_type"), String.class)); + } + else { + throw new IOException("Unknown variant for GSDataType"); + } + } +} \ No newline at end of file diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java new file mode 100644 index 000000000000..e5402a404075 --- /dev/null +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java @@ -0,0 +1,53 @@ +package com.alibaba.graphscope.groot.service.deserializer; + +import com.alibaba.graphscope.groot.service.models.GSDataType; +import com.alibaba.graphscope.groot.service.models.StringTypeString; +import com.alibaba.graphscope.groot.service.models.VarChar; +import com.alibaba.graphscope.groot.service.models.VarCharVarChar; +import com.alibaba.graphscope.groot.service.models.FixedCharChar; +import com.alibaba.graphscope.groot.service.models.LongText; +import com.alibaba.graphscope.groot.service.models.FixedChar; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.io.IOException; + + + +public class StringTypeStringDeserializer extends JsonDeserializer { + public StringTypeStringDeserializer() { + } + + @Override + public StringTypeString deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode node = jp.getCodec().readTree(jp); + System.out.println("StringTypeStringDeserializer"); + System.out.println(node); + + if (node.has("var_char")) { + System.out.println("var_char"); + VarCharVarChar varChar = new VarCharVarChar(); + if (node.get("var_char").has("max_length")) { + // return new VarChar(new VarCharVarChar(jp.getCodec().treeToValue(node.get("var_char").get("max_length"), String.class))); + varChar.setMaxLength(node.get("var_char").get("max_length").asInt()); + } + else { + throw new IOException("max_length not found in var_char"); + } + return new VarChar(varChar); + } else if (node.has("long_text")) { + return new LongText(jp.getCodec().treeToValue(node.get("long_text"), String.class)); + } else if (node.has("fixed_char")){ + return new FixedChar(jp.getCodec().treeToValue(node.get("fixed_char"), FixedCharChar.class)); + } else { + throw new IOException("Unknown variant for GSDataType"); + } + } +} \ No newline at end of file diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java new file mode 100644 index 000000000000..40a11c99d430 --- /dev/null +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java @@ -0,0 +1,39 @@ +package com.alibaba.graphscope.groot.service.deserializer; + +import com.alibaba.graphscope.groot.service.models.GSDataType; +import com.alibaba.graphscope.groot.service.models.StringType; +import com.alibaba.graphscope.groot.service.models.TemporalType; +import com.alibaba.graphscope.groot.service.models.TimeStampType; +import com.alibaba.graphscope.groot.service.models.TemporalTypeTemporal; +import com.alibaba.graphscope.groot.service.models.DateType; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.io.IOException; + + + +public class TemporalTypeTemporalDeserializer extends JsonDeserializer { + public TemporalTypeTemporalDeserializer() { + } + + @Override + public TemporalTypeTemporal deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode node = jp.getCodec().readTree(jp); + + if (node.has("date32")) { + return jp.getCodec().treeToValue(node, DateType.class); + } else if (node.has("timestamp")) { + return jp.getCodec().treeToValue(node, TimeStampType.class); + } else { + throw new IOException("Unknown variant for GSDataType"); + } + } +} \ No newline at end of file From fa111b82b664649ac6f60e1f46f38d8c72b7fe78 Mon Sep 17 00:00:00 2001 From: "xiaolei.zl@alibaba-inc.com" Date: Tue, 14 Jan 2025 09:47:16 +0800 Subject: [PATCH 4/5] fixing Committed-by: xiaolei.zl@alibaba-inc.com from Dev container --- .../sdk/examples/python/basic_example.py | 14 ++---- flex/openapi/openapi_interactive.yaml | 6 ++- .../deserializer/GSDataTypeDeserializer.java | 48 ++++++++++++------ .../StringTypeStringDeserializer.java | 50 +++++++++++-------- .../TemporalTypeTemporalDeserializer.java | 42 +++++++++------- .../groot/service/models/GSDataType.java | 33 ++++++++++++ .../service/models/StringTypeString.java | 33 ++++++++++++ .../service/models/TemporalTypeTemporal.java | 33 ++++++++++++ 8 files changed, 194 insertions(+), 65 deletions(-) create mode 100644 interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java create mode 100644 interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java create mode 100644 interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java diff --git a/flex/interactive/sdk/examples/python/basic_example.py b/flex/interactive/sdk/examples/python/basic_example.py index d77bfbe90c24..198ffed815e2 100644 --- a/flex/interactive/sdk/examples/python/basic_example.py +++ b/flex/interactive/sdk/examples/python/basic_example.py @@ -19,10 +19,6 @@ import os import time - -import sys -sys.path.append(os.path.join(os.path.dirname(__file__), "../../python/")) - from gs_interactive.client.driver import Driver from gs_interactive.client.session import Session from gs_interactive.models import * @@ -42,15 +38,15 @@ "properties": [ { "property_name": "id", - "property_type": {"type_name": "PrimitiveType", "primitive_type": "DT_SIGNED_INT64"}, + "property_type": {"primitive_type": "DT_SIGNED_INT64"}, }, { "property_name": "name", - "property_type": {"type_name": "StringType", "string": {"long_text": ""}}, + "property_type": {"string": {"long_text": ""}}, }, { "property_name": "age", - "property_type": {"type_name": "TimeStampType", "primitive_type": "DT_SIGNED_INT32"}, + "property_type": {"primitive_type": "DT_SIGNED_INT32"}, }, ], "primary_keys": ["id"], @@ -69,7 +65,7 @@ "properties": [ { "property_name": "weight", - "property_type": {"type_name": "PrimitiveType","primitive_type": "DT_DOUBLE"}, + "property_type": {"primitive_type": "DT_DOUBLE"}, } ], "primary_keys": [], @@ -332,4 +328,4 @@ def addEdge(sess: Session, graph_id: str): addEdge(sess, graph_id) getEdge(sess, graph_id) - updateEdge(sess, graph_id) + updateEdge(sess, graph_id) \ No newline at end of file diff --git a/flex/openapi/openapi_interactive.yaml b/flex/openapi/openapi_interactive.yaml index 019d2a5552a5..bad56d032afa 100644 --- a/flex/openapi/openapi_interactive.yaml +++ b/flex/openapi/openapi_interactive.yaml @@ -1326,8 +1326,8 @@ components: properties: primitive_type: type: string - # enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64, - # DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] + enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64, + DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING] # The DT_STRING is added for backward compatibility, it should be replaced by StringType example: DT_SIGNED_INT32 LongText: @@ -1387,6 +1387,7 @@ components: properties: timestamp: type: string + nullable: true DateType: x-body-name: date_type type: object @@ -1395,6 +1396,7 @@ components: properties: date32: type: string + nullable: true TemporalType: x-body-name: temporal_type type: object diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java index 764a60b294ca..2d6f5af9c952 100644 --- a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/GSDataTypeDeserializer.java @@ -1,30 +1,41 @@ +/* + * Copyright 2022 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.graphscope.groot.service.deserializer; import com.alibaba.graphscope.groot.service.models.GSDataType; -import com.alibaba.graphscope.groot.service.models.StringType; import com.alibaba.graphscope.groot.service.models.PrimitiveType; +import com.alibaba.graphscope.groot.service.models.StringType; import com.alibaba.graphscope.groot.service.models.StringTypeString; -import com.alibaba.graphscope.groot.service.models.TemporalTypeTemporal; import com.alibaba.graphscope.groot.service.models.TemporalType; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.DeserializationContext; +import com.alibaba.graphscope.groot.service.models.TemporalTypeTemporal; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; - - public class GSDataTypeDeserializer extends JsonDeserializer { - public GSDataTypeDeserializer() { - } + public GSDataTypeDeserializer() {} @Override public GSDataType deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + throws IOException, JsonProcessingException { JsonNode node = jp.getCodec().readTree(jp); ObjectMapper mapper = (ObjectMapper) jp.getCodec(); System.out.println("GSDataTypeDeserializer"); @@ -35,12 +46,17 @@ public GSDataType deserialize(JsonParser jp, DeserializationContext ctxt) stringType.setString(mapper.treeToValue(node.get("string"), StringTypeString.class)); return stringType; } else if (node.has("temporal")) { - return new TemporalType(jp.getCodec().treeToValue(node.get("temporal"), TemporalTypeTemporal.class)); - } else if (node.has("primitive_type")){ - return new PrimitiveType(jp.getCodec().treeToValue(node.get("primitive_type"), String.class)); - } - else { + // ObjectMapper objectMapper = new ObjectMapper(); + TemporalType temporalType = new TemporalType(); + temporalType.setTemporal( + mapper.treeToValue(node.get("temporal"), TemporalTypeTemporal.class)); + return temporalType; + } else if (node.has("primitive_type")) { + return new PrimitiveType( + PrimitiveType.PrimitiveTypeEnum.fromValue( + jp.getCodec().treeToValue(node.get("primitive_type"), String.class))); + } else { throw new IOException("Unknown variant for GSDataType"); } } -} \ No newline at end of file +} diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java index e5402a404075..523ab82cdf12 100644 --- a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/StringTypeStringDeserializer.java @@ -1,32 +1,40 @@ +/* + * Copyright 2022 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.graphscope.groot.service.deserializer; -import com.alibaba.graphscope.groot.service.models.GSDataType; +import com.alibaba.graphscope.groot.service.models.FixedChar; +import com.alibaba.graphscope.groot.service.models.FixedCharChar; +import com.alibaba.graphscope.groot.service.models.LongText; import com.alibaba.graphscope.groot.service.models.StringTypeString; import com.alibaba.graphscope.groot.service.models.VarChar; import com.alibaba.graphscope.groot.service.models.VarCharVarChar; -import com.alibaba.graphscope.groot.service.models.FixedCharChar; -import com.alibaba.graphscope.groot.service.models.LongText; -import com.alibaba.graphscope.groot.service.models.FixedChar; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; - - public class StringTypeStringDeserializer extends JsonDeserializer { - public StringTypeStringDeserializer() { - } + public StringTypeStringDeserializer() {} @Override public StringTypeString deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + throws IOException, JsonProcessingException { JsonNode node = jp.getCodec().readTree(jp); System.out.println("StringTypeStringDeserializer"); System.out.println(node); @@ -35,19 +43,21 @@ public StringTypeString deserialize(JsonParser jp, DeserializationContext ctxt) System.out.println("var_char"); VarCharVarChar varChar = new VarCharVarChar(); if (node.get("var_char").has("max_length")) { - // return new VarChar(new VarCharVarChar(jp.getCodec().treeToValue(node.get("var_char").get("max_length"), String.class))); + // return new VarChar(new + // VarCharVarChar(jp.getCodec().treeToValue(node.get("var_char").get("max_length"), + // String.class))); varChar.setMaxLength(node.get("var_char").get("max_length").asInt()); - } - else { + } else { throw new IOException("max_length not found in var_char"); } return new VarChar(varChar); } else if (node.has("long_text")) { return new LongText(jp.getCodec().treeToValue(node.get("long_text"), String.class)); - } else if (node.has("fixed_char")){ - return new FixedChar(jp.getCodec().treeToValue(node.get("fixed_char"), FixedCharChar.class)); + } else if (node.has("fixed_char")) { + return new FixedChar( + jp.getCodec().treeToValue(node.get("fixed_char"), FixedCharChar.class)); } else { throw new IOException("Unknown variant for GSDataType"); } } -} \ No newline at end of file +} diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java index 40a11c99d430..728f2390ad04 100644 --- a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/deserializer/TemporalTypeTemporalDeserializer.java @@ -1,39 +1,45 @@ +/* + * Copyright 2022 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.graphscope.groot.service.deserializer; -import com.alibaba.graphscope.groot.service.models.GSDataType; -import com.alibaba.graphscope.groot.service.models.StringType; -import com.alibaba.graphscope.groot.service.models.TemporalType; -import com.alibaba.graphscope.groot.service.models.TimeStampType; -import com.alibaba.graphscope.groot.service.models.TemporalTypeTemporal; import com.alibaba.graphscope.groot.service.models.DateType; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.DeserializationContext; +import com.alibaba.graphscope.groot.service.models.TemporalTypeTemporal; +import com.alibaba.graphscope.groot.service.models.TimeStampType; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; - - public class TemporalTypeTemporalDeserializer extends JsonDeserializer { - public TemporalTypeTemporalDeserializer() { - } + public TemporalTypeTemporalDeserializer() {} @Override public TemporalTypeTemporal deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + throws IOException, JsonProcessingException { JsonNode node = jp.getCodec().readTree(jp); if (node.has("date32")) { - return jp.getCodec().treeToValue(node, DateType.class); + return new DateType(); } else if (node.has("timestamp")) { - return jp.getCodec().treeToValue(node, TimeStampType.class); + return new TimeStampType(); } else { throw new IOException("Unknown variant for GSDataType"); } } -} \ No newline at end of file +} diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java new file mode 100644 index 000000000000..a17cd2596630 --- /dev/null +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.graphscope.groot.service.models; + +import com.alibaba.graphscope.groot.service.deserializer.GSDataTypeDeserializer; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.*; + +import javax.annotation.Generated; +import javax.validation.constraints.*; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NONE) +@JsonDeserialize(using = GSDataTypeDeserializer.class) +@Generated( + value = "org.openapitools.codegen.languages.SpringCodegen", + date = "2025-01-13T19:18:58.368636+08:00[Asia/Shanghai]", + comments = "Generator version: 7.10.0") +public interface GSDataType {} diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java new file mode 100644 index 000000000000..4acadfa0a372 --- /dev/null +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.graphscope.groot.service.models; + +import com.alibaba.graphscope.groot.service.deserializer.StringTypeStringDeserializer; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.*; + +import javax.annotation.Generated; +import javax.validation.constraints.*; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NONE) +@JsonDeserialize(using = StringTypeStringDeserializer.class) +@Generated( + value = "org.openapitools.codegen.languages.SpringCodegen", + date = "2025-01-13T19:18:58.368636+08:00[Asia/Shanghai]", + comments = "Generator version: 7.10.0") +public interface StringTypeString {} diff --git a/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java new file mode 100644 index 000000000000..10177290ee5f --- /dev/null +++ b/interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Alibaba Group Holding Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.graphscope.groot.service.models; + +import com.alibaba.graphscope.groot.service.deserializer.TemporalTypeTemporalDeserializer; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.*; + +import javax.annotation.Generated; +import javax.validation.constraints.*; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NONE) +@JsonDeserialize(using = TemporalTypeTemporalDeserializer.class) +@Generated( + value = "org.openapitools.codegen.languages.SpringCodegen", + date = "2025-01-13T19:18:58.368636+08:00[Asia/Shanghai]", + comments = "Generator version: 7.10.0") +public interface TemporalTypeTemporal {} From 37a2f634bb66297ef159e04b83dcc58e3f92a60d Mon Sep 17 00:00:00 2001 From: "xiaolei.zl@alibaba-inc.com" Date: Tue, 14 Jan 2025 09:48:18 +0800 Subject: [PATCH 5/5] minor Committed-by: xiaolei.zl@alibaba-inc.com from Dev container --- flex/interactive/sdk/examples/python/basic_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flex/interactive/sdk/examples/python/basic_example.py b/flex/interactive/sdk/examples/python/basic_example.py index 198ffed815e2..f53209a77600 100644 --- a/flex/interactive/sdk/examples/python/basic_example.py +++ b/flex/interactive/sdk/examples/python/basic_example.py @@ -328,4 +328,4 @@ def addEdge(sess: Session, graph_id: str): addEdge(sess, graph_id) getEdge(sess, graph_id) - updateEdge(sess, graph_id) \ No newline at end of file + updateEdge(sess, graph_id)