Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

jira 2227 : support json fuction - JSON_OBJECT_FIELD_TEXT #833

Merged
merged 10 commits into from
Dec 6, 2016

Conversation

andyyangcn
Copy link
Contributor

add json parser code and a new json fucntion : JSON_OBJECT_FIELD_TEXT('json string', 'key').

@Traf-Jenkins
Copy link

Can one of the admins verify this patch?

3 similar comments
@Traf-Jenkins
Copy link

Can one of the admins verify this patch?

@Traf-Jenkins
Copy link

Can one of the admins verify this patch?

@Traf-Jenkins
Copy link

Can one of the admins verify this patch?

@moscowgentalman
Copy link
Contributor

jenkins, test

@moscowgentalman
Copy link
Contributor

@svarnau , please help to take a look

@svarnau
Copy link
Contributor

svarnau commented Nov 14, 2016

jenkins, add user

@Traf-Jenkins
Copy link

Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1355/

@Traf-Jenkins
Copy link

Copy link
Contributor

@moscowgentalman moscowgentalman left a comment

Choose a reason for hiding this comment

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

this is a big check-in, will need to take some time to review the code. Some initial comments embedded.

@@ -0,0 +1,1139 @@
#include "stringinfo.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Must add license info at the header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -3925,3 +3925,16 @@ $3~String1.
30047 ZZZZZ 99999 BEGINNER MAJOR DBADMIN NAR details. HexdRow: $0~String0 ErrNum: $1~Int1 ObjectName: $2~TableName PartitionName: $3~String3 FileNum: $4~Int4 RecNum: $5~Int5
30048 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Fast Load failed. Number of error rows($0~Int0) inserted into the exception table exceeded the max allowed($1~Int1).
30049 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Fast Load succeeded. Number of error rows inserted into the exception table is $0~Int0

32001 ZZZZZ 99999 BEGINNER MAJOR DBADMIN Token is invalid.
32002 ZZZZZ 99999 BEGINNER MAJOR DBADMIN JSON value is invalid.
Copy link
Contributor

Choose a reason for hiding this comment

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

if possible, considering use 8000~8999 range for function run-time error?
I am not very sure here, need @zellerh, @DaveBirdsall to review as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agree. Maybe something like 8970-8982.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,124 @@
#ifndef JSON_H
Copy link
Contributor

Choose a reason for hiding this comment

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

license header is required

Copy link
Contributor

@zellerh zellerh Nov 14, 2016

Choose a reason for hiding this comment

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

Yes, and also please try to follow the naming conventions for source file names. For example, this file in the common directory should probably be called ComJSON.h or similar. That should make it much easier to find. Otherwise, if someone would come across a name like json.cpp or json.h, they would assume that it is not part of Trafodion and/or they would have to do quite a bit of searching to figure out where the file comes from. Overall, I think the idea of putting the JSON-related code into the common directory is a very good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


if (str->data != NULL)
free(str->data);
str->data = (char *) malloc(newlen);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I haven't reviewed all of the code. Is there a chance that we will introduce memory leaks? Would it make sense to pass a Trafodion heap pointer (NAMemory *) to a StringInfo object, so we can control the memory allocation better?

* to doing a pure parse with no side-effects, and is therefore exactly
* what the json input routines do.
*
* The 'fname' and 'token' strings passed to these actions are palloc'd.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments talk about palloc, but we really use malloc in this code. See another comment about whether malloc is the right thing to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Postgresql uses palloc function to allocate memories from memory pool. So, when I porting the code, I remove that part and use malloc as a replace. For postgresql, developer doesn't need to care about when to release the memory, because when the request is completed, all memory allocated in the request will be release. I'm not sure if Trafodion has the same mechanism to manage memory, if yes, I can use that to replace palloc.

@zellerh
Copy link
Contributor

zellerh commented Nov 14, 2016

Much of this code is a copy of the PostgreSQL source code. You cannot strip off the PostgreSQL license header and copyright from these files. I'm not quite sure how this should be handled, but my guess would be that you need to leave the PostgreSQL license header in the file and add the Apache License header as well. Also, you may need to add an entry to the RAT_README file in the top-level directory. See also http://www.apache.org/legal/resolved.html, this states that it is ok to include PostgreSQL code in an Apache project. Maybe @gtapper, our new Release Manager, can help you with the details. Our previous release manager, @robertamarton, has a lot of experience with this.

int cursor;
} StringInfoData;

typedef StringInfoData *StringInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

"StringInfo" is a very generic term and this struct is used for a very specialized purpose here. It would be good to rename it to make it more clear what it is for. For example: ComJSONStringInfo would make it more clear that this is part of the common directory and used for JSON strings. Also, it is not common in Trafodion to typedef a pointer to a regular name, and this will probably confuse people as well. Is it possible to use the Trafodion strings NAString or NAText instead? NAText is basically the same as std::string. Just a question, I realize that it may be too much work to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Absolutely right. Such code would also have to be documented in licenses/lic-server-src that is used to build the LICENSE file that goes out with the released code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -33735,7 +33741,6 @@ nonreserved_func_word: TOK_ABS
| TOK_FLOOR
| TOK_FN
| TOK_GREATEST
| TOK_GROUPING_ID
Copy link
Contributor

Choose a reason for hiding this comment

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

should not remove GROUPING_ID, must be accidental?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

merge mistake. add it back.

@Traf-Jenkins
Copy link

New Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1358/

@Traf-Jenkins
Copy link

@Traf-Jenkins
Copy link

Previous Test Aborted. New Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1359/

@Traf-Jenkins
Copy link

@Traf-Jenkins
Copy link

New Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1360/

@Traf-Jenkins
Copy link

@Traf-Jenkins
Copy link

New Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1368/

@Traf-Jenkins
Copy link

int len = _state->lex->prev_token_terminator - start;

//_state->tresult = cstring_to_text_with_len(start, len);
_state->tresult = (char *)malloc(len + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

not clear where this malloc memory will be free?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be free in ex_function_json_object_field_text::eval().

if (rltStr != NULL)
{
    Lng32 rltLen = str_len(rltStr)+1;
    str_cpy_all(op_data[0], rltStr, rltLen);
    free(rltStr);

    // If result is a varchar, store the length of substring 
    // in the varlen indicator.
    if (getOperand(0)->getVCIndicatorLength() > 0)
        getOperand(0)->setVarLength(rltLen, op_data[-MAX_OPERANDS]);
}

@moscowgentalman
Copy link
Contributor

moscowgentalman commented Nov 18, 2016

overall looks good to me. +1 from me.
There are two following tasks for this though, it is OK to finish them in following check-ins instead of this one:

  1. Since this impact the document, please file a JIRA to track the task of update SQL Reference Manual about this new function.
  2. Add some test case, so others will be better understanding how this works.

@andyyangcn
Copy link
Contributor Author

A new jira is created to track the task for updating documents.
TRAFODION-2360

@moscowgentalman
Copy link
Contributor

@svarnau , @gtapper do you have concerns from license point of view of merging this PR?

Copy link
Contributor

@svarnau svarnau left a comment

Choose a reason for hiding this comment

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

rat exclude may not be needed.
license file addition looks good.

ComJSON.cpp
ComJSONFuncs.cpp
ComJSONStringInfo.h
ComJSONStringInfo.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if these are needed here, with the copyright restored and the ASF statements added, but I did not try running RAT without to verify.
Would like a better comment here than BSD license - specify PostgresSQL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have removed json files from .rat-excludes

@svarnau
Copy link
Contributor

svarnau commented Nov 23, 2016

In good shape from license file view.

@robertamarton
Copy link
Contributor

robertamarton commented Nov 25, 2016 via email

@Traf-Jenkins
Copy link

Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1409/

@Traf-Jenkins
Copy link

@moscowgentalman
Copy link
Contributor

@andyyangcn , you need to fix the conflicts

Do a 'git pull' and fix the merge issue, and commit again.

@Traf-Jenkins
Copy link

New Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1433/

@Traf-Jenkins
Copy link

@asfgit asfgit merged commit 7dbfdb3 into apache:master Dec 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
7 participants