You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Austin Duncan <ad...@pyaanalytics.com> on 2017/10/23 18:56:44 UTC
Select Query With Aliases
I am using an executesql processor to perform a select query. I want to
select data from a table and have the column names displayed as something
else (alias). Example would be select answer_1 as "how_did_it_go" from
schema.table. When I run a flowfile through it it queries the data but the
alias is not applied. Does nifi not have this functionality or is there
something wrong with my query. Thanks
--
Austin Duncan
*Researcher*
PYA Analytics
2220 Sutherland Avenue
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
Knoxville, TN 37919
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
423-260-4172
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
<%28865%29%20684-2828>
Re: Select Query With Aliases
Posted by Austin Duncan <ad...@pyaanalytics.com>.
I tried using the method in which the reader has the schema and the writer
has a new schema with the new names but it gets rid of the data that was
selected in the query. any idea why?
On Mon, Oct 23, 2017 at 4:55 PM, Matt Burgess <ma...@gmail.com> wrote:
> Austin,
>
> Once you convert from Avro to CSV you can probably use ReplaceText to
> do what you want with the column names. For now, ExecuteSQL only
> outputs Avro so it has to normalize the names, which includes
> replacing the spaces. I have written NIFI-4517 [1] to track a new
> processor (or changed feature of the existing one) to allow SQL
> results to be returned in any supported format, as well as making the
> schema available downstream, etc.
>
> In the meantime, if ReplaceText doesn't seem to work, and you know the
> names of the columns you'd like to "re-rename", you can use
> UpdateRecord to do the same thing. You just need the Reader to know
> the Avro schema (or use the embedded one), and have the writer use the
> output schema (with the desired names). As long as the writer doesn't
> have the original Avro field names in it, I believe they will be
> ignored in the output, thereby effectively renaming the
> fields/columns.
>
> Just for completeness, if anyone is converting Avro to JSON and has an
> older version of NiFi without the record-aware processors, you can use
> JoltTransformJSON to rename the fields (since ReplaceText would be too
> brittle).
>
> Regards,
> Matt
>
> [1] https://issues.apache.org/jira/browse/NIFI-4517
>
>
> On Mon, Oct 23, 2017 at 3:58 PM, Austin Duncan <ad...@pyaanalytics.com>
> wrote:
> > I figured it out. My avro schema was rewriting the column names after I
> was
> > aliasing haha. Related question. Is there a way to make it so that I can
> use
> > spaces instead of underscores (it says that spaces are an illegal
> character)
> > or is it possible for me to erase the first row and replace it with the
> > column names that I want. I am converting the avro schema into a csv.
> >
> > On Mon, Oct 23, 2017 at 3:03 PM, Matt Burgess <ma...@apache.org>
> wrote:
> >>
> >> Austin,
> >>
> >> What version of NiFi are you using? There was an issue with aliases
> >> (at least for MySQL) before NiFi 1.1.0, fixed by NIFI-3064 [1]. Also
> >> what database and driver version are you using? Since NiFi 1.1.0, we
> >> are following the JDBC 4 spec which says the drivers (when
> >> getColumnLabel is called) should be returning the alias for the
> >> column, if not it will have the column name. If the driver doesn't
> >> comply with that (for example Postgres, which I think returns null),
> >> we will call getColumnName() instead. Depending on your DB and driver,
> >> you might be getting the column name returned by getColumnLabel,
> >> instead of the alias which is the correct thing to return. In that
> >> case I don't think there's anything NiFi can do about it, since the
> >> JDBC would be out of spec at that point.
> >>
> >> Regards,
> >> Matt
> >>
> >> [1] https://issues.apache.org/jira/browse/NIFI-3064
> >>
> >> On Mon, Oct 23, 2017 at 2:56 PM, Austin Duncan <
> aduncan@pyaanalytics.com>
> >> wrote:
> >> > I am using an executesql processor to perform a select query. I want
> to
> >> > select data from a table and have the column names displayed as
> >> > something
> >> > else (alias). Example would be select answer_1 as "how_did_it_go" from
> >> > schema.table. When I run a flowfile through it it queries the data but
> >> > the
> >> > alias is not applied. Does nifi not have this functionality or is
> there
> >> > something wrong with my query. Thanks
> >> >
> >> > --
> >> > Austin Duncan
> >> > Researcher
> >> >
> >> > PYA Analytics
> >> > 2220 Sutherland Avenue
> >> > Knoxville, TN 37919
> >> > 423-260-4172
> >
> >
> >
> >
> > --
> > Austin Duncan
> > Researcher
> >
> > PYA Analytics
> > 2220 Sutherland Avenue
> > Knoxville, TN 37919
> > 423-260-4172
>
--
Austin Duncan
*Researcher*
PYA Analytics
2220 Sutherland Avenue
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
Knoxville, TN 37919
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
423-260-4172
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
<%28865%29%20684-2828>
Re: Select Query With Aliases
Posted by Matt Burgess <ma...@gmail.com>.
Austin,
Once you convert from Avro to CSV you can probably use ReplaceText to
do what you want with the column names. For now, ExecuteSQL only
outputs Avro so it has to normalize the names, which includes
replacing the spaces. I have written NIFI-4517 [1] to track a new
processor (or changed feature of the existing one) to allow SQL
results to be returned in any supported format, as well as making the
schema available downstream, etc.
In the meantime, if ReplaceText doesn't seem to work, and you know the
names of the columns you'd like to "re-rename", you can use
UpdateRecord to do the same thing. You just need the Reader to know
the Avro schema (or use the embedded one), and have the writer use the
output schema (with the desired names). As long as the writer doesn't
have the original Avro field names in it, I believe they will be
ignored in the output, thereby effectively renaming the
fields/columns.
Just for completeness, if anyone is converting Avro to JSON and has an
older version of NiFi without the record-aware processors, you can use
JoltTransformJSON to rename the fields (since ReplaceText would be too
brittle).
Regards,
Matt
[1] https://issues.apache.org/jira/browse/NIFI-4517
On Mon, Oct 23, 2017 at 3:58 PM, Austin Duncan <ad...@pyaanalytics.com> wrote:
> I figured it out. My avro schema was rewriting the column names after I was
> aliasing haha. Related question. Is there a way to make it so that I can use
> spaces instead of underscores (it says that spaces are an illegal character)
> or is it possible for me to erase the first row and replace it with the
> column names that I want. I am converting the avro schema into a csv.
>
> On Mon, Oct 23, 2017 at 3:03 PM, Matt Burgess <ma...@apache.org> wrote:
>>
>> Austin,
>>
>> What version of NiFi are you using? There was an issue with aliases
>> (at least for MySQL) before NiFi 1.1.0, fixed by NIFI-3064 [1]. Also
>> what database and driver version are you using? Since NiFi 1.1.0, we
>> are following the JDBC 4 spec which says the drivers (when
>> getColumnLabel is called) should be returning the alias for the
>> column, if not it will have the column name. If the driver doesn't
>> comply with that (for example Postgres, which I think returns null),
>> we will call getColumnName() instead. Depending on your DB and driver,
>> you might be getting the column name returned by getColumnLabel,
>> instead of the alias which is the correct thing to return. In that
>> case I don't think there's anything NiFi can do about it, since the
>> JDBC would be out of spec at that point.
>>
>> Regards,
>> Matt
>>
>> [1] https://issues.apache.org/jira/browse/NIFI-3064
>>
>> On Mon, Oct 23, 2017 at 2:56 PM, Austin Duncan <ad...@pyaanalytics.com>
>> wrote:
>> > I am using an executesql processor to perform a select query. I want to
>> > select data from a table and have the column names displayed as
>> > something
>> > else (alias). Example would be select answer_1 as "how_did_it_go" from
>> > schema.table. When I run a flowfile through it it queries the data but
>> > the
>> > alias is not applied. Does nifi not have this functionality or is there
>> > something wrong with my query. Thanks
>> >
>> > --
>> > Austin Duncan
>> > Researcher
>> >
>> > PYA Analytics
>> > 2220 Sutherland Avenue
>> > Knoxville, TN 37919
>> > 423-260-4172
>
>
>
>
> --
> Austin Duncan
> Researcher
>
> PYA Analytics
> 2220 Sutherland Avenue
> Knoxville, TN 37919
> 423-260-4172
Re: Select Query With Aliases
Posted by Austin Duncan <ad...@pyaanalytics.com>.
I figured it out. My avro schema was rewriting the column names after I was
aliasing haha. Related question. Is there a way to make it so that I can
use spaces instead of underscores (it says that spaces are an illegal
character) or is it possible for me to erase the first row and replace it
with the column names that I want. I am converting the avro schema into a
csv.
On Mon, Oct 23, 2017 at 3:03 PM, Matt Burgess <ma...@apache.org> wrote:
> Austin,
>
> What version of NiFi are you using? There was an issue with aliases
> (at least for MySQL) before NiFi 1.1.0, fixed by NIFI-3064 [1]. Also
> what database and driver version are you using? Since NiFi 1.1.0, we
> are following the JDBC 4 spec which says the drivers (when
> getColumnLabel is called) should be returning the alias for the
> column, if not it will have the column name. If the driver doesn't
> comply with that (for example Postgres, which I think returns null),
> we will call getColumnName() instead. Depending on your DB and driver,
> you might be getting the column name returned by getColumnLabel,
> instead of the alias which is the correct thing to return. In that
> case I don't think there's anything NiFi can do about it, since the
> JDBC would be out of spec at that point.
>
> Regards,
> Matt
>
> [1] https://issues.apache.org/jira/browse/NIFI-3064
>
> On Mon, Oct 23, 2017 at 2:56 PM, Austin Duncan <ad...@pyaanalytics.com>
> wrote:
> > I am using an executesql processor to perform a select query. I want to
> > select data from a table and have the column names displayed as something
> > else (alias). Example would be select answer_1 as "how_did_it_go" from
> > schema.table. When I run a flowfile through it it queries the data but
> the
> > alias is not applied. Does nifi not have this functionality or is there
> > something wrong with my query. Thanks
> >
> > --
> > Austin Duncan
> > Researcher
> >
> > PYA Analytics
> > 2220 Sutherland Avenue
> > Knoxville, TN 37919
> > 423-260-4172
>
--
Austin Duncan
*Researcher*
PYA Analytics
2220 Sutherland Avenue
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
Knoxville, TN 37919
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
423-260-4172
<https://maps.google.com/?q=2220+Sutherland+AvenueKnoxville,+TN+37919+865&entry=gmail&source=g>
<%28865%29%20684-2828>
Re: Select Query With Aliases
Posted by Matt Burgess <ma...@apache.org>.
Austin,
What version of NiFi are you using? There was an issue with aliases
(at least for MySQL) before NiFi 1.1.0, fixed by NIFI-3064 [1]. Also
what database and driver version are you using? Since NiFi 1.1.0, we
are following the JDBC 4 spec which says the drivers (when
getColumnLabel is called) should be returning the alias for the
column, if not it will have the column name. If the driver doesn't
comply with that (for example Postgres, which I think returns null),
we will call getColumnName() instead. Depending on your DB and driver,
you might be getting the column name returned by getColumnLabel,
instead of the alias which is the correct thing to return. In that
case I don't think there's anything NiFi can do about it, since the
JDBC would be out of spec at that point.
Regards,
Matt
[1] https://issues.apache.org/jira/browse/NIFI-3064
On Mon, Oct 23, 2017 at 2:56 PM, Austin Duncan <ad...@pyaanalytics.com> wrote:
> I am using an executesql processor to perform a select query. I want to
> select data from a table and have the column names displayed as something
> else (alias). Example would be select answer_1 as "how_did_it_go" from
> schema.table. When I run a flowfile through it it queries the data but the
> alias is not applied. Does nifi not have this functionality or is there
> something wrong with my query. Thanks
>
> --
> Austin Duncan
> Researcher
>
> PYA Analytics
> 2220 Sutherland Avenue
> Knoxville, TN 37919
> 423-260-4172