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 xmltype in postgres #1112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mauravan
Copy link

Motivation:

see #1111

I'm looking for a little guidance on this.

  1. where can i find an integration test i could use to test against while implementing?
  2. maybe some pointers on where to start

thanks
R

@mauravan mauravan marked this pull request as draft December 21, 2021 21:40
@vietj vietj added this to the 4.2.4 milestone Dec 22, 2021
@vietj
Copy link
Member

vietj commented Dec 22, 2021

@mauravan you can look at the existing tests of other PG specific data type and add tests in their location

@vietj
Copy link
Member

vietj commented Dec 22, 2021

I'm curious, did you try using a string ?

@mauravan
Copy link
Author

mauravan commented Dec 22, 2021

that's why im looking for an integration test - i suspect we might be able to use a String as long as we pass it as UTF8. Then we could just remove the wrapper class.

i did not have a lot of time to look into it, but i will have some time soon and will dig a bit deeper

@mauravan
Copy link
Author

mauravan commented Dec 22, 2021

Hi @vietj,

So turns out we might as well use String. Or do you think there is value in an extra class like the PgSQLXML i added? otherwise i will happily remove it.

Also what needs to happen next to get this merged?

Thanks for your help,
R

EDIT: I just tried this with quarkus and i think it's really unhandy to have to use an extra class for this when we could be using String - will change this

EDIT2: So i did it using String now and it works just fine i think - one problem i encountered was the mapping in the DataType.java because there is already a mapping for String to Varchar

encodingTypeToDataType.put(String.class, VARCHAR); encodingTypeToDataType.put(String[].class, VARCHAR_ARRAY); encodingTypeToDataType.put(String.class, XML); encodingTypeToDataType.put(String[].class, XML_ARRAY);

Which seems to be only important in case of a PrepareStatementCommand with parameterTypes which the test i'm executing are apparently not using. Maybe you have some more insight into that?

@vietj
Copy link
Member

vietj commented Dec 24, 2021

this needs to be reviewed to be merged

@mauravan mauravan changed the title add draft for xmltype in postgres add xmltype in postgres Dec 25, 2021
@mauravan mauravan marked this pull request as ready for review December 25, 2021 11:43
@vietj vietj modified the milestones: 4.2.4, 4.2.5 Jan 20, 2022
@@ -229,5 +220,8 @@ static DataType lookup(Class<?> type) {
encodingTypeToDataType.put(Polygon[].class, POLYGON_ARRAY);
encodingTypeToDataType.put(Circle.class, CIRCLE);
encodingTypeToDataType.put(Circle[].class, CIRCLE_ARRAY);

// encodingTypeToDataType.put(String.class, XML);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented ?

Copy link
Author

@mauravan mauravan Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the Comment from the 22. of Dec:

So i did it using String now and it works just fine i think - one problem i encountered was the mapping in the DataType.java because there is already a mapping for String to Varchar

encodingTypeToDataType.put(String.class, VARCHAR); encodingTypeToDataType.put(String[].class, VARCHAR_ARRAY); encodingTypeToDataType.put(String.class, XML); encodingTypeToDataType.put(String[].class, XML_ARRAY);

Which seems to be only important in case of a PrepareStatementCommand with parameterTypes which the test i'm executing are apparently not using. Maybe you have some more insight into that?

@vietj
Copy link
Member

vietj commented Jan 26, 2022

this PR changes a lot of things that should not be changed (like reformatting), can you keep only to the essential changes ?

Roman Meier added 2 commits January 31, 2022 10:32
Signed-off-by: Roman Meier <[email protected]>
Signed-off-by: Roman Meier <[email protected]>
@mauravan
Copy link
Author

this PR changes a lot of things that should not be changed (like reformatting), can you keep only to the essential changes ?

Hi @vietj, thanks for the feedback - i reverted all the changes.

The one big Problem with the private static final IntObjectMap<DataType> oidToDataType = new IntObjectHashMap<>(); remains. this structure does not allow for a duplicate mapping of String.

One solution i could think of is to use a wrapper class for XML which would then just hold the String. Do you have any other ideas?

@vietj
Copy link
Member

vietj commented Jan 31, 2022

why is it an issue ?

@mauravan
Copy link
Author

mauravan commented Jan 31, 2022

There is these 2 cases for the Map:

static DataType valueOf(int oid) {
    DataType value = oidToDataType.get(oid);
    if (value == null) {
      logger.debug("Postgres type OID=" + oid + " not handled - using unknown type instead");
      return UNKNOWN;
    } else {
      return value;
    }
  }

  static DataType lookup(Class<?> type) {
    DataType dataType = encodingTypeToDataType.get(type);
    if (dataType == null) {
      if (Buffer.class.isAssignableFrom(type)) {
        return BYTEA;
      }
      dataType = DataType.UNKNOWN;
    }
    return dataType;
  }

Where for the valueOf Method we have a mapping for each oid for the lookup i think there can only be a mapping per type. So either the Mapping is

encodingTypeToDataType.put(String.class, XML); encodingTypeToDataType.put(String[].class, XML_ARRAY);

Or it is
encodingTypeToDataType.put(String.class, VARCHAR); encodingTypeToDataType.put(String[].class, VARCHAR_ARRAY);
The lookup seems to be called during encoding and the valueOf during decoding. So it seems to me, that encoding of String -> varchar would be disabled?

@vietj vietj modified the milestones: 4.2.5, 4.2.6 Feb 16, 2022
@vietj vietj modified the milestones: 4.2.6, 4.2.7 Mar 17, 2022
@vietj vietj modified the milestones: 4.2.7, 4.2.8 Apr 13, 2022
@@ -186,8 +186,11 @@ static DataType lookup(Class<?> type) {
for (DataType dataType : values()) {
oidToDataType.put(dataType.id, dataType);
}
encodingTypeToDataType.put(String.class, VARCHAR);
encodingTypeToDataType.put(String[].class, VARCHAR_ARRAY);
// encodingTypeToDataType.put(String.class, VARCHAR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand it, there can only be one mapping per class to a Type. This is the Problem i was talking about in the other comments which we need to solve here - so either there will be a need for a wrapper class or someone can come up with a better solution for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are totally right, this is because we cannot specify which database type to use in a tuple for a given java type

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there will be something like a new Class like PgXMLType which just holds a String. Would you agree to that?

@vietj vietj modified the milestones: 4.4.4, 4.4.5 Jun 22, 2023
@vietj vietj modified the milestones: 4.4.5, 4.4.6 Aug 30, 2023
@vietj vietj modified the milestones: 4.4.6, 4.5.0 Sep 12, 2023
@vietj vietj modified the milestones: 4.5.0, 4.5.1 Nov 15, 2023
@vietj vietj modified the milestones: 4.5.1, 4.5.2 Dec 13, 2023
@vietj vietj modified the milestones: 4.5.2, 4.5.3 Jan 30, 2024
@vietj vietj modified the milestones: 4.5.3, 4.5.4 Feb 6, 2024
@vietj vietj modified the milestones: 4.5.4, 4.5.5 Feb 22, 2024
@vietj vietj modified the milestones: 4.5.5, 4.5.6 Mar 14, 2024
@vietj vietj modified the milestones: 4.5.6, 4.5.7, 4.5.8 Mar 21, 2024
@vietj vietj modified the milestones: 4.5.8, 4.5.9 May 24, 2024
@vietj vietj modified the milestones: 4.5.9, 4.5.10 Jul 17, 2024
@vietj vietj modified the milestones: 4.5.10, 4.5.11 Sep 4, 2024
@vietj vietj modified the milestones: 4.5.11, 4.5.12 Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants