Re: Issue while calling new PostgreSQL command from a Java Application

Lists: pgsql-hackers
From: Ashoke <s(dot)ashoke(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Issue while calling new PostgreSQL command from a Java Application
Date: 2014-07-04 05:13:12
Message-ID: CALpszJPXFBb+0w-thEk=6vNP-ZRgqn1i+PX8xonp=cZ_DqNJRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

------------------------------

I have defined a new command my_command in PostgreSQL. This command takes
the path of ANALYZE and inside analyze.c, I have a function to do some
operations if its my_command.This command takes the input arguments: table
name, column name and an input string.

my_command nation (n_nationkey) 'input string';

When I run this command from command line psql, it works as expected. But
when I call the same command from a java application, the variable that
stores the input string is NULL.

I printed the value of the input string in gram.y file where I have defined
my_command.
fprintf (stderr, "I am inside gram.y %s\n",n->inp_str); and the input
string is printed correctly.

But when I print stmt->inp_str in the function standard_ProcessUtility() of
utility.c for the case T_VacuumStmt, I get the value as NULL. This is as
far as I could trace back from analyze.c.

I am not sure how executing the same command from an application can make a
difference.

gram.y content gist:
------------------------------

MyStmt:
my_keyword qualified_name name_list my_inp_str
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_ANALYZE;
n->freeze_min_age = -1;
n->freeze_table_age = -1;
n->relation = $2;
n->va_cols = $3;
n->inp_str = $4;
fprintf (stderr, "I am inside gram.y %s\n",n->inp_str);

$$ = (Node *)n;
};

char *inp_str is added to the struct VacuumStmt in parsenodes.h

---------------------------

Only the newly added char *inp_str(that is different from ANALYZE) value is
NULL. I was able to retrieve the column name from va_cols.

Any help is appreciated. Thanks!
--
Regards,
Ashoke


From: Abhijit Menon-Sen <ams(at)2ndQuadrant(dot)com>
To: Ashoke <s(dot)ashoke(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Issue while calling new PostgreSQL command from a Java Application
Date: 2014-07-04 06:18:50
Message-ID: 20140704061850.GB11067@toroid.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

At 2014-07-04 10:43:12 +0530, s(dot)ashoke(at)gmail(dot)com wrote:
>
> I am not sure how executing the same command from an application can
> make a difference.

It shouldn't make any difference, of course.

But since you're seeing the problem with new code, the overwhelming
probability is that there's an error in the new code. That being the
case, speculating about what might be going wrong without looking at
the code in question is a waste of time.

-- Abhijit


From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: Ashoke <s(dot)ashoke(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Issue while calling new PostgreSQL command from a Java Application
Date: 2014-07-04 06:19:04
Message-ID: CAFjFpRep9g=FjT36pEJKUThZPyVoZb=XiODVrJzuv1en-NB0AQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

You may have to add code to copy inp_str to _copyVacuumStmt(). See how a
character array being copied from other _copy* functions.

On Fri, Jul 4, 2014 at 10:43 AM, Ashoke <s(dot)ashoke(at)gmail(dot)com> wrote:

> Hi,
>
> ------------------------------
>
> I have defined a new command my_command in PostgreSQL. This command takes
> the path of ANALYZE and inside analyze.c, I have a function to do some
> operations if its my_command.This command takes the input arguments:
> table name, column name and an input string.
>
> my_command nation (n_nationkey) 'input string';
>
> When I run this command from command line psql, it works as expected. But
> when I call the same command from a java application, the variable that
> stores the input string is NULL.
>
> I printed the value of the input string in gram.y file where I have
> defined my_command.
> fprintf (stderr, "I am inside gram.y %s\n",n->inp_str); and the input
> string is printed correctly.
>
> But when I print stmt->inp_str in the function standard_ProcessUtility()
> of utility.c for the case T_VacuumStmt, I get the value as NULL. This is
> as far as I could trace back from analyze.c.
>
> I am not sure how executing the same command from an application can make
> a difference.
>
> gram.y content gist:
> ------------------------------
>
> MyStmt:
> my_keyword qualified_name name_list my_inp_str
> {
> VacuumStmt *n = makeNode(VacuumStmt);
> n->options = VACOPT_ANALYZE;
> n->freeze_min_age = -1;
> n->freeze_table_age = -1;
> n->relation = $2;
> n->va_cols = $3;
> n->inp_str = $4;
> fprintf (stderr, "I am inside gram.y %s\n",n->inp_str);
>
> $$ = (Node *)n;
> };
>
> char *inp_str is added to the struct VacuumStmt in parsenodes.h
>
> ---------------------------
>
> Only the newly added char *inp_str(that is different from ANALYZE) value
> is NULL. I was able to retrieve the column name from va_cols.
>
> Any help is appreciated. Thanks!
> --
> Regards,
> Ashoke
>
>
>

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company


From: Ashoke <s(dot)ashoke(at)gmail(dot)com>
To: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Issue while calling new PostgreSQL command from a Java Application
Date: 2014-07-04 07:00:48
Message-ID: CALpszJPfm8jAOez8AEU17bQKGbBJGeqLtC3PVLyqN_x9em1BdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thank you Ashutosh*.* That was the issue. But, could you please explain why
it worked from command line?

On Fri, Jul 4, 2014 at 11:49 AM, Ashutosh Bapat <
ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:

> You may have to add code to copy inp_str to _copyVacuumStmt(). See how a
> character array being copied from other _copy* functions.
>
>
> On Fri, Jul 4, 2014 at 10:43 AM, Ashoke <s(dot)ashoke(at)gmail(dot)com> wrote:
>
>> Hi,
>>
>> ------------------------------
>>
>> I have defined a new command my_command in PostgreSQL. This command
>> takes the path of ANALYZE and inside analyze.c, I have a function to do
>> some operations if its my_command.This command takes the input
>> arguments: table name, column name and an input string.
>>
>> my_command nation (n_nationkey) 'input string';
>>
>> When I run this command from command line psql, it works as expected.
>> But when I call the same command from a java application, the variable that
>> stores the input string is NULL.
>>
>> I printed the value of the input string in gram.y file where I have
>> defined my_command.
>> fprintf (stderr, "I am inside gram.y %s\n",n->inp_str); and the input
>> string is printed correctly.
>>
>> But when I print stmt->inp_str in the function standard_ProcessUtility()
>> of utility.c for the case T_VacuumStmt, I get the value as NULL. This
>> is as far as I could trace back from analyze.c.
>>
>> I am not sure how executing the same command from an application can make
>> a difference.
>>
>> gram.y content gist:
>> ------------------------------
>>
>> MyStmt:
>> my_keyword qualified_name name_list my_inp_str
>> {
>> VacuumStmt *n = makeNode(VacuumStmt);
>> n->options = VACOPT_ANALYZE;
>> n->freeze_min_age = -1;
>> n->freeze_table_age = -1;
>> n->relation = $2;
>> n->va_cols = $3;
>> n->inp_str = $4;
>> fprintf (stderr, "I am inside gram.y %s\n",n->inp_str);
>>
>> $$ = (Node *)n;
>> };
>>
>> char *inp_str is added to the struct VacuumStmt in parsenodes.h
>>
>> ---------------------------
>>
>> Only the newly added char *inp_str(that is different from ANALYZE) value
>> is NULL. I was able to retrieve the column name from va_cols.
>>
>> Any help is appreciated. Thanks!
>> --
>> Regards,
>> Ashoke
>>
>>
>>
>
>
> --
> Best Wishes,
> Ashutosh Bapat
> EnterpriseDB Corporation
> The Postgres Database Company
>

--
Regards,
Ashoke


From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: Ashoke <s(dot)ashoke(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Issue while calling new PostgreSQL command from a Java Application
Date: 2014-07-04 07:51:30
Message-ID: CAFjFpRdK2ah5u0-v+JD1zszYKiRoXLERitM15okpyiM=+ttSaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jul 4, 2014 at 12:30 PM, Ashoke <s(dot)ashoke(at)gmail(dot)com> wrote:

> Thank you Ashutosh*.* That was the issue. But, could you please explain
> why it worked from command line?
>
>
I do not know. Any time we add a member to a node and find it's value
coming out NULL or 0 instead of the one set, corresponding _copy* is the
first suspect. You may be able find why it worked in command line and why
not through the connector by breaking on copyObject() in either cases.

>
> On Fri, Jul 4, 2014 at 11:49 AM, Ashutosh Bapat <
> ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
>
>> You may have to add code to copy inp_str to _copyVacuumStmt(). See how a
>> character array being copied from other _copy* functions.
>>
>>
>> On Fri, Jul 4, 2014 at 10:43 AM, Ashoke <s(dot)ashoke(at)gmail(dot)com> wrote:
>>
>>> Hi,
>>>
>>> ------------------------------
>>>
>>> I have defined a new command my_command in PostgreSQL. This command
>>> takes the path of ANALYZE and inside analyze.c, I have a function to do
>>> some operations if its my_command.This command takes the input
>>> arguments: table name, column name and an input string.
>>>
>>> my_command nation (n_nationkey) 'input string';
>>>
>>> When I run this command from command line psql, it works as expected.
>>> But when I call the same command from a java application, the variable that
>>> stores the input string is NULL.
>>>
>>> I printed the value of the input string in gram.y file where I have
>>> defined my_command.
>>> fprintf (stderr, "I am inside gram.y %s\n",n->inp_str); and the input
>>> string is printed correctly.
>>>
>>> But when I print stmt->inp_str in the function standard_ProcessUtility()
>>> of utility.c for the case T_VacuumStmt, I get the value as NULL. This
>>> is as far as I could trace back from analyze.c.
>>>
>>> I am not sure how executing the same command from an application can
>>> make a difference.
>>>
>>> gram.y content gist:
>>> ------------------------------
>>>
>>> MyStmt:
>>> my_keyword qualified_name name_list my_inp_str
>>> {
>>> VacuumStmt *n = makeNode(VacuumStmt);
>>> n->options = VACOPT_ANALYZE;
>>> n->freeze_min_age = -1;
>>> n->freeze_table_age = -1;
>>> n->relation = $2;
>>> n->va_cols = $3;
>>> n->inp_str = $4;
>>> fprintf (stderr, "I am inside gram.y %s\n",n->inp_str);
>>>
>>> $$ = (Node *)n;
>>> };
>>>
>>> char *inp_str is added to the struct VacuumStmt in parsenodes.h
>>>
>>> ---------------------------
>>>
>>> Only the newly added char *inp_str(that is different from ANALYZE)
>>> value is NULL. I was able to retrieve the column name from va_cols.
>>>
>>> Any help is appreciated. Thanks!
>>> --
>>> Regards,
>>> Ashoke
>>>
>>>
>>>
>>
>>
>> --
>> Best Wishes,
>> Ashutosh Bapat
>> EnterpriseDB Corporation
>> The Postgres Database Company
>>
>
>
>
> --
> Regards,
> Ashoke
>
>
>
>
>

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ashoke <s(dot)ashoke(at)gmail(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Issue while calling new PostgreSQL command from a Java Application
Date: 2014-07-04 14:10:20
Message-ID: 19482.1404483020@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Ashoke <s(dot)ashoke(at)gmail(dot)com> writes:
> Thank you Ashutosh*.* That was the issue. But, could you please explain why
> it worked from command line?

Simple vs extended query protocol, probably --- the former avoids copying
the constructed parsetree, but I think the latter doesn't. Or maybe the
JDBC driver tried to prepare the query; a prepared statement is most
certainly going to copy the parsetree.

In general, if you add a field to any node type, you'd better go through
backend/nodes/ and teach all the relevant functions about it. What I tend
to do is grep for one of the existing fields in the struct and see which
functions that reference it need additions.

regards, tom lane