-
Notifications
You must be signed in to change notification settings - Fork 180
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
Record and Record Array functionality #16
Comments
yes, it's good idea to add support for pg composite type. i'll try to implement it. i did some researching these days, but need more time before i start coding. will keep you posted for the updates. |
Cool :D thanks. I've been looking into it as well, doing it properly that is. Already having problems with regular expressions when it comes to parsing strings. I think we need a lifted representation of a record, and use that description to parse and generate records. What do you think ? |
I've started coding for it. |
aaah you around, I started looking into it more last night. Have you found a way to parse the array / composite value strings ? I couldn't find any java code that does it in the postgres JDBC libraries, I could only find a basic tokenizer that doesn't seem to do much. Are you going to write your own parser ? |
yes, maybe |
This guy goes into some detail of the issues of parsing postgres custom types. Are you going to allow nested arrays / composites ? I think that should definitely be covered as I was doing an hstore of I was making use of pythons psyopg2 in my work, it dealt very well with composite types. I have some experience with writing parsers/tokenisers, Would you like me to look into writing a tokeniser for the composite type using the scala parser combinator library ? If you have it under control I'll get out of your way <3. On a separate note, I'm currently still writing postgres ddl. If we had arrays and composites along with all the stuff you already implemented. I could do all the ddl off of the the lifted representation. I mention this, because in this case we would need a lifted representation of the composite type. All we need is something like this :
|
yes, it's good help. please my basic way is,
for lifted representation, yes, we need it if we want to add ddl support for it. |
Ok I will start by writing a tokeniser as follows. I will make a list of test strings covering:
I will then write a level 1 tokeniser for this. Which puts the tokens onto a stack. I guess a Level 2 tokeniser should reduce the stack into level 2 tokens of case class ValueToken, ArrayToken, CompositeToken. From here we should be able to map the data. We can add other level 1 tokens, and reduction cases later on for new types. |
ok, thanks again. |
I've implemented integer / decimal nested array / record parsing so far adding strings next.
|
cool |
Seems nested records/arrays have a quotation format depending on depth. Level 1 is unquoted
Ouch and it gets crazier for strings
I just figured monads out a few days ago (sort of). I think I need to change the parser monad to track the depth,
omg the quotes and backslashes follow power 2^n depending on depth. Ok I have figured out a way of dealing with it :D |
Hi @hsyed, I submitted some draft codes to new branch Will be enhanced and refactorred. |
Cool. I made it to a parse that handled almost everything but I couldn't get past the quotation problem. I decided to write a tokeniser first. The output is as follows :
I will rewrite this list and keep only those markers that signify opening and closing strings. I will further reduce those quotation markers to a single ", or a double for strings that have '' in them. Then I'll run it through a parser. Sigh it seems I haven't catered for escapes but good thing escapes have a regular pattern which you can verify with
Ok Quotations and escapes are tokenising correctly :D
|
Do you have any advise on how you would like me to proceed ? The output above is useable, but I could parse it further. The parser I was working on is here so have a look at it and tell me what you want. I think you probably want the arrays and records grouped so :
Do you want me to parse what I can when it comes to the value types ? I think you will have to check the value types so there isn't much value in me parsing beyond just tokenising them, and it is probably better to do it outside of the parser. These are the value type parsing I got to before.
If you don't need any further parsing I'll probably write a simple function for grouping things together. |
hi @hsyed, i think you already did enough, and no more parsing will be needed. btw, for value type, i think Can you send me a pull request? to branch Thanks again! |
Heya, ok I finished the tokeniser and merger. This is what it does now.
This is my first piece of open source work :D Next thing we need is Asynchronous Upsert operations supported at the ORM level. That + hstore/gist/gin + records = nosql in postgres :D Postgres doesn't seem to have merge support so the asynchronous element would have to be done in an actor I guess. |
hi @hsyed, great job. and i did some refactoring according parsed result structure as below: //TODO analog @hsyed's implementation, should be deleted later
sealed trait Element
case class ValueE(value: String) extends Element
case class ArrayE(elements: List[Element]) extends Element
case class CompositeE(members: List[Element]) extends Element here is the latest codes. and you can see some simple tests at the bottom. Will do more refactoring when applying it to |
See comment in pull request :D |
hi @hsyed, i merged your changes into |
hi @hsyed, you'd better to send a pull request to branch I'd like your name appeared in the contributors ^^ |
hi @hsyed, we also need a generator from I already implemented the function which consumes BTW, i did some refactoring for your codes, to codes unification and be convenient for using again, thanks so much for your nice contribution^^ |
I just made two important functions tail recursive. Performance should be good now. Sure, what do you have in mind ? "Array[Row()]" style of doing it ? I didn't get a chance to make sense of the way postgres interleaves quotes and backslashes. Array[Row()] is probably not bad anyway, considering at nested level 4 your already doing 2^3 of interleaved \ or ". |
thanks for your enhancement^^ well, I already implemented: so I want a (ps: we needn't care |
Ok this will not be a problem with Array and Row annotation. Although I seem to remember issues with JDBC in the past when it came to composite data and Array and Row. ( I can't remember but I might have had to do a Could you do the following for me :
I ask for 1 because I don't have much experience with JDBC, and I ask for 2 because I was developing the parser code in a messy project with messy tests. It would be easier if I open the slick-pg project in the IDE directly and I don't have any experience on who to write unit tests with scala :D My hack of inserting arrays of composites which started this feature request, produces the following SQL. As you can see this doesn't use
|
Ok, I'll do them next morning (ps: it's midnight in my time now :D), and give you updates. |
Ok cool :D Are you Chinese ? My wife is from china and is in Hong Kong on business at the moment :D |
yes, I lived in Xiamen, China, same timezone with Hong Kong :D |
What a coincidence. My wifes family is from xiamen, her Parents live in Fuzhou though. I spent Chinese new year in Xiamen a few years ago :D |
Just an FYI,
I hacked together a way of doing records and array of records. I started working on it from this Stackoverflow question.
The adapted mappers are here .
It's based on regular expressions and pattern matching. Rather nasty. Hope you guys can come up with a nicer way of doing it and add it to the project <3. There should be away of generating matchers and regular expressions from the case classes, but my scala metaprogramming skills suxor :D I need records in hstore in the next few days. I'm dreading having to alter hstore as the operator support looks tasty, and I would want those features.
P.s., sorry if this is not the right place to put this. I don't know feature requests go.
Regards
Hassan
The text was updated successfully, but these errors were encountered: