How to avoid duplication of headers when exporting CSV from SSRS - ssrs-2012

I'm trying to export .csv from SQL Server Reporting Services 2012.
The output is like:
I want output like:
Header1 Header2
Data1 Data2
Data3 Data4
How can I achieve this?

Related

Can I grep to find matching rows in 2 files using grep+cut but then print back the rest of the row after the cut?

I am looking to find matches anywhere between 2 csv files, email addresses specifically.
If I run this command via bash (I would like to figure out something via bash for now):
grep -w --file <(sort -u file1.csv) <(sort -u file2.csv| cut d',' -f2)
it works. But there is surrounding character data in the same row that I would like to print out either to stdin or to a new file eventually. How do I do this diff comparison and still preserve the row data for printing?
file1.csv consists of:
email#email.com
file2.csv consists of:
,email#.email.com,123456,"""ABC, Blah Blah."""
I would like to do my comparison but join the ABC, Blah Blah data back to the final result.
Thank you!
When having to query data from CSV tables; joining on index like with your email index; SQLite3 is an appropriate tool choice.
It is a nice, common and standard tool to have:
Capable of directly importing CSV files.
Available for many different platforms.
Widely used, light-weight database engine with SQL query language.
Here is an example:
file1.csv:
email
email#example.com
someone#example.com
file2.csv:
email,phone,description
email#email.com,123456,"""ABC, Blah Blah."""
someone#example.com,7684652,"Foo, bar, baz."
anything#example.net,424255,"Hello kitten"
email#example.com,6578218,"This to be output"
When your CSV files have column headers, SQLite3 handles tables creation for you, using columns' name from the CSV:
#! /bin/sh
sqlite3 :memory: << 'EOF'
.mode csv
.headers on
.import file1.csv emails
.import file2.csv contacts
SELECT c.*
FROM emails AS e
LEFT JOIN contacts AS c
ON e.email = c.email;
EOF
Here is how it all works:
sqlite3 :memory:: Invokes SQLite3 with in-memory database.
.mode csv: Places SQLite3 in CSV mode, so it can work directly with CSV files.
.headers on: Activates output of columns' header.
.import file1.csv emails: Imports file1.csv into the emails table.
.import file2.csv contacts: Imports file2.csv into the contacts table.
Here is the actual SQL query, that will SELECT * all columns from the contacts AS c table; when the c.email = e.email columns matches with the LEFT JOINed emails AS e table:
SELECT c.*
FROM emails AS e
LEFT JOIN contacts AS c
ON e.email = c.email;
When CSV files don't have columns' headers; tables need be created explicitly with SQL commands before importing the CSV into it:
CREATE TABLE emails (
email text NOT NULL PRIMARY KEY
);
CREATE TABLE contacts (
email text NOT NULL PRIMARY KEY,
phone text,
description text
);
Output from this program above:
email,phone,description
email#example.com,6578218,"This to be output"
someone#example.com,7684652,"Foo, bar, baz."

Impala query results export to csv file only if it fetches any row

I want to export query results from Impala to a csv file through UNIX shell script. I want to write to csv only if the query returns any rows. If it doesn't return any row, the code should send mail saying no records found. If the impala query returns any row, it should write to a csv file.
My current script can export results to csv. But when no rows are fetched, a blank csv gets generated.
impala_connection="impala-shell -k --ssl -i 1.1.1.1"
mail_id="abc#def.com"
status="Fail"
query="select process_id, batch_id, job_name, status_cd from table_name where status_cd=\"$status\";"
$impala_shell -B -q "$query" -o /local/job_failures.csv '--output_delimiter=,'

How to extract apache phoenix table/view data to a file

How can I extract data from an apache phoenix table/view to CSV/PSV/text?
For ex query:
select * from test_view
After connecting to phoenix with sqlline.py:
phoenix-sqlline zk4-habsem.lzmf1fzmprtezol2fr25obrdth.jx.internal.cloudapp.net,zk5-habsem.lzmf1fzmprtezol2fr25obrdth.jx.internal.cloudapp.net,zk1-habsem.lzmf1fzmprtezol2fr25obrdth.jx.internal.cloudapp.net:2181:/hbase-unsecure
which format do you want exported file
!outputformat csv
Mension local file path
!record data.csv
Phoenix query which we want to export into file
select * from tableName
!record
!quit
File is saved in /home/user/data.csv
You can use squirrel to extract the data to local file.
Refer
https://community.hortonworks.com/articles/44350/setting-up-squirrel-and-phoenix-integration.html

Update Oracle database with content of text file

I would like to update a field in an Oracle database with the content of a standard txt file.
The file is generated every 10 minutes by an external program on which i do not have control.
I would like to create a job in oracle or a SQLPLUS batch file that would pick the content of the file and update a specific record in an ORACLE Database
For exemple My_Table would contains this:
ID Description FileContent
-- ----------- ---------------------------------------------------------
00 test1.txt This is content of test.txt
01 test2.txt Content of files may
Contain several lines
blank lines
pretty much everything (but must be limited to 2000char)
02 test3.txt not loaded yet
My file "test3.txt" changes often but i do no know when and would look like this:
File generated at 3:33 on august 19, 2016
Result :
1 Banana
2 Apple
3 Pineapple
END OF FILE
i would like the full content of the file to be loaded up into it's corresponding record in an Oracle Database.

Creating schema using pig script

I need some guidance/help with a simple task to create a schema in Apache Pig for my data file. I have two files that would contribute to this task. First file is a data file which contains the data with no column header, and a second file contains the column header for the data file. So basically, the column_header file is the schema for the data file. How do i outline this in a pig script? Here's what i got so far.
column_header = load 'sitecatalyst/coulmn_headers.tsv' using PigStorage('\t');
data = load 'sitecatalyst/hit_data.tsv' using PigStorage('\t') as column_header;
schema = foreach data generate column_header;
store schema into 'output1' using PigStorage('\t', '-schema');
withSchema = load 'output1';
describe withSchema;
This is the output for
DUMP column_header
(accept_language,browser,browser_height,browser_width)
When i do,
DUMP data;
only the first line column of data is being output, which is wrong.
en-US
en-US
en-US
en-US
Instead it should be,
en-US 638 755 1600
en-US 638 655 1342
en-US 638 723 1612
en-US 638 231 1234
How can i trick Pig to use "column_header" as a string that can be use during the PigStorage AS statement on the second line of code?
Edit:
This code will work but instead of hard-coding my column_header i would like pig script to read it instead.
column_header = load 'sitecatalyst/coulmn_headers.tsv' using PigStorage('\t');
data = load 'sitecatalyst/hit_data.tsv' using PigStorage('\t') as (accept_language,browser,browser_height,browser_width);
schema = foreach data generate accept_language,browser,browser_height,browser_width;
store schema into 'output1' using PigStorage('\t', '-schema');
withSchema = load 'output1';
describe withSchema;
you can not achieve such parameterization from in the pig script directly,
you can to the same thing by
data = load 'sitecatalyst/hit_data.tsv' using PigStorage('\t') as $column_header;
schema = foreach data generate column_header;
store schema into 'output1' using PigStorage('\t', '-schema');
withSchema = load 'output1';
describe withSchema;
and run the pig script by ,
pig -param_file (location of the file) column
The file should be of the format
column_header = complete schema
https://blogs.msdn.microsoft.com/bigdatasupport/2014/08/12/how-to-use-parameter-substitution-with-pig-latin-and-powershell/

Resources