Showing posts with label Netezza. Show all posts
Showing posts with label Netezza. Show all posts

Monday, 2 November 2015

Estimating database and table size in Netezza

Estimating database and table size and skew in Netezza


nz_db_size utility present in /nz/support/contrib/3.1/bin/ can be used to estimate the total number of bytes on disk that a given database and the tables belonging to the database is occupying:


Usage is as follows:

nz_db_size [ -s ] [ database [ table ] ]

E.g.:

[nz@nps12345 bin]$ ./nz_db_size MYTESTDB MYTABLE


Object | Name | Bytes | KB | MB | GB | TB
-----------+----------------------------------+---------------------+-----------------+-------------+-----------+--------
Appliance | nps1234 | 134,934,002 | 136,083 | 132,894 | 192.8 | .1
Database | MYTESDB | 123,245,56 | 12
,345,67 | 1000 | 1230 | .0
Table | MYTABLE | 1,206,720 | 1,178 | 1 | .0 | .0


To get summary stats for database use the below command:

[nz@mpc-nps]$ nz_db_size -summary -s

  Object   |               Name               |        Bytes         |        KB        |      MB      |     GB     |   TB
-----------+----------------------------------+----------------------+------------------+--------------+------------+--------
 Appliance | mpc-nps                   |    1,34343,2434,24 |   1,232,32,23232,34 |    2,167,756 |    4,2267 |    2.1
 Database  | MYTESTDB                          |      123,2323,3232,33 |      123,345,343|      456,334|      686.0 |     .7


nz_stats is another command that can be used be get the full statistics:

For example: nzstats show -type table


Using SQLCMD to execute SQL scripts from a file on SQL server machine in Informatica

Using SQLCMD to execute SQL scripts from a file on SQL server machine


I was wondering how to execute a SQL script  using Informatica cloud on SQL server. The obvious approach that came to mind was using the SQL transformation in script mode. That approach works but cannot be implemented in Informatica cloud since SQL transformation is not supported in Informatica. The next approach that came to mind was to use some tool that can execute SQL script on SQL server. Happened to find out about this tool called the SQLCMD that can do the task for you.
You can put all the commands you want to execute in a .sql file or .txt file and then execute the script using the SQLCMD utility. In the below example, all the SQL  commands are in C;\test_sql.txt

You will most likely find the tool in the below location on the machine that has microsoft managment studio installed.

cd C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Bin

If you want to execute the SQLCMD command in window authentication mode use the below command:

SQLCMD -S myservermachine -i C:\test_sql.txt -o C:\out.txt

If you want to execute the SQLCMD command in window authentication mode as a different user then use  the below command:

RUNAS /user:Mydomain\myusername "SQLCMD -S myservermachine -i C:\test_sql.txt -o C:\out.txt"

If you want to execute the SQLCMD command in sql server  authentication mode use the below command:

SQLCMD -U myusername -P mypass -S myservermachine -i C:\test_sql.txt -o C:\out.txt

Using NZSQL to execute SQL scripts from a file on Netezza machine

Similary nzsql tool can be used SQL scripts from a file on Netezza machine. The command is:

nzsql -f <sql_file_name>


Tuesday, 14 July 2015

How to monitor Netezza performance?

 How to monitor Netezza performance?

Performance of Netezza depends on various factors such as distribution keys on the table, query performance, hardware factors such as number of spus,  data skew i.e. how the data is distributed across the spus, etc

There are different ways to check how your netezza box is performing. First you can use the netezza administration tool to see the number of queries running , queries getting queued, the performance of individual queries. If there are too many queries running then obviously it is going to slow down your server performance. If there are any bad queries pulling lot of data then obviously it will one of the culprit. Put a threshold time out for queries that users are running so that it does not run for ever.You can also check out the netezza performance portal. Provides some extra information on performance.

Data skew on netezza refers to how well the data is distributed on different spus of the netezza server. If some of the spus have more data then the others then it is going to impact the performance. Make sure the data is properly distributed by using appropriate distribution keys.

You can also use certain queries to see the performance of the netezza machine. Some of them are listed below.

To check all the queries running on the system use the below query

select * from SYSTEM..NZ_QUERY_HISTORY

To check the list of successful and all historical queries also try out the below queries:

SELECT * FROM  HIST_admin."$v_hist_successful_queries"

SELECT * FROM  HIST_admin."$v_hist_queries"

select * from   HISTDB.."$v_hist_table_access_stats"

select * from _v_qryhist

select * from _v_qrystat;




We can check distribution of data using performance portal or the netezza administration console, or the explain plan, or nz_skew dba script. 

Wednesday, 10 June 2015

How to enforce primary key constraint in Informatica when loading to netezza?

Does netezza enforce primary key constraint?


Neteza does not enforce primary key constraint. Application that loads data to netezza has to enforce it.

How to enforce primary key constraint in Informatica when loading to netezza?


If Informatica is loading data to netezza you can enforce primary key constrain by setting the primary key constraint in the target definition of Informatica mappings. This allows it to enforce primary key constrain in the current load but does not work if there is data already in the netezza table. For example, if record1 and record2 are duplicate in the current load then Informatica detects it when loading to netezza table. However, if records2 already exists in netezza table, and you are now loading only record1 then Informatica cannot find out about record2.

In this circumtance you have to put additional logic in informatica such as a lookup or filter condition to check for existing records in netezza target table. Hope this helps!!




Monday, 8 June 2015

How to install UDF functions on Netezza?


How to install an user defined function (UDF) in netezza?


Lets says you have got hold of the UDF function from netezza and want to install it then the below steps would help. In the example below, reverse function is installed on netezza server.


How to install UDF functions on Netezza?


 In the folder where you have placed the tgz file execute the below instruction.

[netezzahost]$ gunzip reverse.tgz
[netezzahost]$ tar -xvf reverse.tar

[netezzahost]$ cd reverse

[netezzahost]$ ./install <databasename>

CREATE FUNCTION
Created udf
Done


After this step you might have to execute grant command to provide permission on the function to the users.

For example:

grant execute on reverse to <mygroup>;


Login to database and test the function:

select reverse('mydog');
 REVERSE
---------
 godmy
(1 row)

Thursday, 23 April 2015

Getting view names and definition of view in Netezza

To get list of all the views in Netezza use the below statement:


SELECT viewname FROM _v_view WHERE viewname NOT LIKE '\_%' AND UPPER(objtype) = 'VIEW' ORDER BY viewname;


To get the definition of a view in Netezza  use the below statement. 


SELECT definition FROM _v_view WHERE viewname = <VIEWNAME> AND UPPER(objtype) = 'VIEW';

To get the unique object id associate with the view in Netezza use the below statement:


SELECT objid FROM _v_view WHERE viewname = <VIEWNAME> AND UPPER(objtype) = 'VIEW';


General syntax to create views in Netezza is :

create view vendor_view as select vendor_id, vendor_name from vendor order by vendor_id;

To read about mat views check:


http://dwbitechguru.blogspot.ca/2014/12/what-is-materialized-mat-view-in.html 


Wednesday, 1 April 2015

Netezza datatype conversion function

Netezza datatype conversion function


To convert decimal to integer use cast(value as int) in netezza:


select cast(12345.30 as int)

In the above example in place of 12345.30 you can use any decimal or numeric column.

Thursday, 19 March 2015

Creating DATABASE, GROUPS, USERS , GRANTING PERMISSIONS in Netezza

Creating DATABASE, GROUPS, USERS , GRANTING PERMISSIONS in Netezza

Some of the sample netezza commands to create database, user groups , users, add user to a group, grant permissions to netezza objects is below:


Creating a netezza database, group, and adding user group permissions to that database


\c SYSTEM
CREATE DATABASE <databasename>;

CREATE GROUP <groupname> WITH USER <username1>, <username2>;
GRANT LIST ON
<databasename> TO <groupname> WITH GRANT OPTION;GRANT  Create External Table, Create Sequence, Create Synonym, Create Table, Create Temp Table, Create View TO <groupname> ;

GRANT backup, create sequence, create synonym, create table, create external table, create temp table, create view, restore  TO <groupname> ;

To create a user group in netezza database:


Syntax: CREATE GROUP <groupname>

Example: CREATE GROUP  MYTESTGROUP1;

To alter the settings of the group:


ALTER GROUP "<groupname>" WITH ROWSETLIMIT 0 SESSIONTIMEOUT 0 QUERYTIMEOUT 50 DEFPRIORITY High MAXPRIORITY High;

To create a user and assign to a netezza database user group:


CREATE USER  <username>  WITH PASSWORD '??' IN GROUP "<groupname>";

If user already exists or after you have added a user then you can use the command below to add that user to a group:


ALTER GROUP "<groupname>" ADD USER "<username>";

To provide permission on netezza objects such as tables, views, database etc to a user group or a user use the syntax below:


GRANT List ON "<databasename>" TO "groupname";

GRANT List, Select, ON "<tablename>" TO "groupname";


GRANT delete,genstats,groom,insert,list,select,truncate,update ON <tablename> TO <groupname>;
 

To copy permissions from one table to the other in Netezza:


ALTER TABLE <target_table_name> set privileges to  <target table name>;

To change ownership of a netezza table:

alter table <tablename> owner to <newownername>

The above command change the schema name associated with the table

Tuesday, 23 December 2014

What is Materialized (Mat or Mview) view in Netezza and how is it different from normal views?


 

  What is Materialized (Mat or Mview) view in Netezza ?

Materialized views in Netezza are used to create a new table that contain subset of columns from the base tables and the data sorted by the columns in the new table. These kind of views are used to improve performance since it reduces the width of data being scanned since it creates a thin version of the base table and the data can be sorted in different order than the base table. Example usage of mat view is below:

create materialized view vendor_mview as select vendor_id, vendor_name from vendor order by vendor_id;



The limitation of materialized views in Netezza are:

1) Only one table can be used as the base (source) table.
2) There can be no where clause in the select statement and the columns used in the select must be part of the base table and no expressions can be used in the select statement.
3) Materialized (mat) views can be created from user tables only and cannot be temporary or external tables. 
4) You cannot GROOM a base table with an active materialized view created on top of it.
5) The materialized views needs maintenance since when data is added to the base table, the materialized views also get updated and data is added to the end in unsorted order. Hence, periodically the materialized (mview or mat) views need to be rebuilt.


The command to rebuild materialized view is:

ALTER VIEW <materialized_view_name> MATERIALIZE REFRESH 

How is materialized (mat) view different from normal views in Netezza?

The normal views in Netezza are used to select only required columns from multiple tables and make it look like a single table. Normal views do not create a real table and do not require maintenance when data is added to the base tables.

Normal views in Netezza can be based out of multiple tables, can contain where clause in the select statement, the columns can have expressions and pretty much everything you can have in a select statement. 

Sample create view statement is below:

create view vendor_mview as select vendor_id, vendor_name, product_id, product_name  from vendor, product where vendor.product_id=product.product_id and product_category='cell phone' order by vendor_id;

The normal views do not improve the performance of a query.The use of a normal view is more for convenience where instead of using the same select query multiple times, we can create a view instead and use the view in place of select statement. Also, the view permission can be changed and only few columns exposed to certain users who do not have permission to see all the columns of the base tables.

Check out, selecting distribution key in Netezza:
http://dwbitechguru.blogspot.ca/2014/12/selecting-distribution-key-in-netezza.html 

Selecting proper Distribution Key In Netezza for better query performance

Selecting  proper Distribution Key In Netezza for better query performance


Netezza distributes data across the data slices based on the distribution key. This distribution of data impacts the query performance. The distribution key can be specified during table creation (up to 4 columns can be part of distribution key) or it can be specified to be random which mean Netezza will use round robin algorithm to distributed data on the data slices or if not specified Netezza will pick one of the column as distribution key. Hence, Never create table without a distribution key since that does not guarantee optimal performance.

The data has to distributed uniformly across all the data slices so that all the Netezza SPU (snippets) have same amount of work to do. If the data is some data slices are more than others then some SPU will do more work than others in which case the data distribution is skewed which is bad for Netezza query performance.

In the below example, employee_id column is used as distribution key. The distribution keys are defined using the DISTRIBUTE ON clause.



create table employee (
employee_id integer not null ,
employee_name varchar(25),
employee_dept_id integer,
employee_age integer,
employee_address varchar(25)
) distribute on employee_id;

 
1) When selecting distribution key, choose the columns that have unique values and high cardinality. Hence, primary keys or part of primary key are good choice for distribution key. In the above example, employee ID is unique for all the records hence a good candidate for distribution key.

2) Selecting data ID is not good choice for distribution key. The data might get uniformly distributed across data slices with data ID but if the query requires data from a particular month then only few SPUs might be busy and hence impacting query performance. 


3) If two big tables are joined on certain columns, then better to used those columns as distribution keys.

4) When creating table as (Create table as select * from t1 join t2 on t1.c1=t2.c2) join from two other tables then the distribution keys will be the columns used for joining. If there is a group by clause in the select statement used in  then those group by clause will be the distribution keys. 

5) If there is no good choice for distribution key, then select distribution random instead of not defining any distribution key.

6) Try not to use varchar as a distribution key. Big Int data type or integer data type might be better choice than Varchar. 


We can check distribution of data using performance portal or the netezza administration console, or the explain plan, or nz_skew dba script. 


Explain distribution command gives the data distribution information. For example:

explain distribution select * from employee_table;

Friday, 19 December 2014

How to select between Hadoop vs Netezza vs Redshift- comparison?

How to select between Hadoop vs Netezza vs Redshift- comparison? 

Common question that we here is, among Hadoop, Netezza, and Redshift, which one is better and which one is going to replace everything else? All these technologies have their own pros and cons and it is essential to know those before we try find out ideal use cases for them and how to use them in your ecosystem.

Hadoop:


Pros:
  • As we know hadoop is mainly used for big data purpose i.e purpose where huge volume is involved often peta byte scale or more.
  • The data can be unstructured, stuctured or semi structured.
  • The data in hadoop can be stored on commodity hardware and the cost of storing and processing is less considering the volume of data it can handle. Now lets says we are receiving huge number of XML files, flat files from huge number of sources (for example, sensors from air plane, logs fromfirewalls/IDS systems, tweets from twitter, etc) and needs to be loaded at a rapid pace and processed then hadoop is  an ideal candidate. 
  • The hadoop clusters are highly scalable and it can be horizontally or vertically scaled by adding more commodity hardware and nodes that are not expensive.
  • The hadoop clusters can also be made to handle streaming data, collect data from sensors, store the streaming data, playback etc.
  • Data redundancy is built  into the cluster.

Cons:
  • Point to be noted here are the files if stored on HDFS are going to be in flat file format and though you can use Hive or Impala to process these files as structured data there are some limitation to it. The hive SQL do not offer full functionality that is found in traditional databases.
  • Updating records will be tough and you will have to use tool like HBASE to get this update functionality.
  • Response time of hadoop hive queries are not going to fast as Netezza because at the back ground these program run map reduce jobs that are not as fast as the Netezza. Also, they are meant for huge volumes and used in places where response time are  not that important i.e for batch jobs.
  • Administration of the cluster is not simple like administration of netezza.
Conclusion:

  • If you are doing ELT (Extract Load transform) with huge data loads that can be stored as flat files on HDFS then Hadoop is a good candidate. You can load all the files and then process or transform etc.
  • Volume and scalability are also the deciding factors and Hadoop is deal for big data purpose

Netezza:


Pros:
  • It is a traditional data warehouse appliance that supports traditional SQL statements i.e all DML and DDL statements. Inserts, updates are all possible.
  • Very fast and made for gigabyte scale data warehousing purpose. Depending on the number of SPUs, it can handle gigabytes of data and process it at super fast speed. The data is distributed on multiple SPUs and they all work together to crunch the data.
  • Administration overhead is very less compared to oracle, DB2 , etc data bases.
Cons:
  • Mainly meant for structured data warehouse applications.
  • Probably cannot handle unstructured data of peta byte volumes effectively like Hadoop.

Conclusion:

If you are building traditional data warehouse where you also need to ETL (Extract - Transform- Load) then Netezza is better since you can insert, update, aggregate, etc with ease and write your SQL for reporting and building cubes.

Redshift:


Pros:
  • Peta byte scale computing and cost model based on On demand basis.
  • Traditional data warehousing and SQLs supported.
  • Can handle volume even greater than Netezza and build on the same model as Netezza.
  • On the cloud and minimal administration required
  • Easily scalable and nodes (computing power ) and space can be added with some mouse clicks.
  • Easy to create data snapshots and bring the redshift cluster up and down as and when required.

Cons:
  • On the cloud and data has to be transported to the cloud redshift cluster.
  • Reading huge volumes from ODBC/JDBC connection is still a problem.
  • If there is lot of back and forward movement between the cluster and local network then it creates some latency.
  • Have to get security clearance to get data out of the network
Conclusion:
  • Good for ELT purpose where data is loaded to redshift cluster once and then processing is done on the cluster and aggregate/summarized data is read from the cluster or if the other downstream applications are sourcing the data directly from the redshift cluster.
  • Good for traditional data warehousing purpose.

Tuesday, 16 December 2014

Issue with reading a oracle CLOB column in Informatica and Inserting to Netezza using Netezza PowerCenter Driver:

Issue with reading a oracle CLOB column in Informatica and Inserting to Netezza using Netezza PowerCenter Driver:


Issue: Informatica session failed with the below message when reading a table with a column of CLOB data type.

Severity    Timestamp    Node    Thread    Message Code    Message
ERROR    12/16/2014 11:40:43 AM        NZ_WRT_1_*_1    Net_1762    [ERROR] Failed to execute query : [INSERT INTO "MT TABLE"("MY_KEY", "KEY_DESC", "BATCH_KEY") ...........

The .nzbad showed that all the columns after clob column was going to next line. i.e netezza driver was not able to read properly the | delimited file that it creates while inserting data to the target.

Resolution:
There can be two reasons for this issue, either your clob column is null or you have some new line characters. First I fixed the null issue but the problem still persisted which made me later think that the clob column has some newline or carriage return character. Fixed the issue by using the replacestr function to replace all the new line and carriage return characters.

The expression is below:

IIF(isnull(CLOB_COLUMN_STRING),'  ', REPLACESTR (1,CLOB_COLUMN_STRING,CHR(10),CHR(13), ''))


char(10), char(13) in the expression above stands for newline and carriage return characters.



In the above example CLOB_COLUMN_STRING is the name of the port that belongs to the CLOB table column. In Informatica, clob columns are read as Text data type.

Note: Also, make sure the length of the text port in informatica for the clob column is same as the length of clob column defined in the oracle table.

Wednesday, 10 December 2014

How to create Unix Script to Drop & Truncate Netezza table- or execute any SQL on Netezza

#  Unix Script to Drop & Truncate a Netezza tables
#!/bin/sh
# enter your database name and table name in below

dbname=exampledb
tblname=exampletbl

# use below line to drop a table 
nzsql $dbanme -c "drop table $tblname"
# use below line to truncate a table 
nzsql $dbanme -c "truncate table $tblname"

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

#  Unix Script to Truncate list of Netezza tables
#!/bin/sh
# enter your database name below

dbname=exampledb
table_list=`nzsql $dbane-t -c " select TABLENAME from _V_TABLE where OBJTYPE = 'TABLE' and TABLENAME like 'yourtablelistprefix_%' "`

for table_name in $table_list; do
  echo "Dropping the table $table_name from database $dbname"
  nzsql $dbname -c "truncate table $table_name"

done;

Tuesday, 9 December 2014

Netezza Groom Table to free table space - Netezza Administration

Netezza Groom Table command to reclaim table space -  Netezza Administration

In Netezza when a record is updated, it marks the original record for deletion and inserts a new record with the updated values. So basically it is doing a logical delete. The records marked for deletion are not visible when you do a simple select from a table. However, those records marked for deletion are still available till you groom the table. The same thing happen when you delete records from a table. Those records stay still a table is groomed.  If a table is not groomed regularly it can impact the performance since those deleted records also need to be scanned. Hence, Grooming tables is essential as part of Netezza Administration.

If you want to remove those logically deleted records and free up space, then groom the table.

A simple groom command to reclaim all deleted records would be:


GROOM TABLE <tablename> RECORDS ALL;


Groom command to reorganize new data that is added  to previously groomed table is :

GROOM TABLE <tablename> RECORDS READY;


Note:
1) You do not have to groom a table after truncating a table since truncating a table deletes all the records permanently

2) Groom is non blocking however it is resource intensive so better to schedule it weekly or monthly or during backup operation.

3) Netezza Groom replaces reclaim operation so you do not have to use reclaim operation after groom.

You can find other options available for the groom command here:
https://www-304.ibm.com/support/knowledgecenter/SSULQD_7.1.0/com.ibm.nz.dbu.doc/r_dbuser_groom_table.html



Wednesday, 19 November 2014

Netezza NZSQL, NZLOAD, NZ_MIGRATE, NZUNLOAD utility to Extract - Load - Migrate Files/Data

Netezza NZSQL, NZLOAD, NZ_MIGRATE, NZUNLOAD utility to Extract - Load - Migrate Files/Data 

Extract - Load - Migrate Files/Data to/from Netezza


It is very easy in Netezza to extract data from netezza tables, load data from files to Netezza target tables, or Migrate data from one Netezza database to another.Below are few commands that you can use this purpose.

NZSQL utility: This utility can be run from any machine on which it is installed i.e. it does not have be from netezza box itself. This utility can be used to run any sql statement like select or insert statement on the netezza database. In the below usage you see data extracted from the table into a output file and in the second mzsql command the data is also gzipped.

Usage:

nzsql -host <netezz_db_servername> -d <database> -u <username> -pw <password> -c  -c  "select * from tablename"  -o /root/home/outputfilename.txt;


nzsql -host <netezza_db_servername> -d <database> -u <username> -pw <password> -c  "select * from tablename" -F "|" -A -q -t | gzip > /root/home/outputfilename.txt.gz;

nzsql -host <netezza_db_servername> -d <database> -u <username> -pw <password> -c  'insert into tablename values (1 ,2 )'  -o /root/home/outputfilename.txt;

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

NZLOAD utility: This utility can be used to load data from files to netezza target tables. The nzload command usage is below. In the usage below the flat file which is delimited by | is loaded to a table mentioned with in <target_table_name>. Also user name and password can be provided for this utility.

nzload -host <netezzahost> -db <database> -u <user name>
       -pw <password> -delim '|' -t <target_table_name> -df /root/home/outputfilename.txt



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

NZ_MIGRATE utility: this utility is used to migrate data from source database to the target database. All the tables mentioned in the tablelist parameter are migrated to the target database. There are options to create target tables or truncate target tables before migrating the data. NZ_Migrate utility does the migration by running many parallel threads and hence is faster than nzload.


nz_migrate command usage is below:

./nz_migrate -shost <source_host> -thost <target_host> -sdb <source_database> -tdb <targetdatabase> -suser <source_user> -spassword <source_password> -tuser <target_user> -tpassword <target_password> -t <table1, table2, ...> -cksum fast -genStats Full  -TruncateTargetTable YES >> $log


./nz_migrate -shost <source_host> -thost <target_host> -sdb <source_database> -tdb <targetdatabase> -suser <source_user> -spassword <source_password> -tuser <target_user> -tpassword <target_password> -t <table1, table2, ...> -cksum fast -genStats Full  -CreateTargetTable YES>> $log

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

NZ_UNLOAD utility: if instead of nzsql you want to extract files from a netezza table faster by running multiple threads in parallel then use nz_unload utility. The nz_unload command usage is below:

./nz_unload -sql '"select * from tablename"' -file /nz/dba/output/outputfilename.txt

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

External tables: Another way to migrate data is to create external table and insert the data from external table into the targer table. External table usage would like shown below:

CREATE EXTERNAL TABLE '/tmp/export.csv' USING (DELIM ',') AS
SELECT * from <TABLENAME>;


INSERT INTO <targettable> SELECT * FROM external '/tmp/export.csv'
USING (DELIM ',');


Monday, 8 September 2014

Commonly used netezza date functions and how to do data manipulations?

How to use date functions in Netezza?

--to select the current date and timestamp use:


select current_date
select current_timestamp 

--to add months and convert date to integer use:

select to_number(to_char(add_months(current_date, -1),'YYYYMMDD'),'99999999') --to get date id

select to_number(to_char(add_months(current_date, -1),'YYYYMM'),'9999999') --to get month id

select date(current_date -  cast('1 month' as interval))

--to convert timestamp to yyyy-mm-dd format:


select TO_CHAR(TO_DATE('2011-11-24 22:42:28','YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD')
select TO_CHAR(current_timestamp,'YYYY-MM-DD')

--to extract year part from the current date

select extract (year from current_date)
select date_trunc('year', current_date)
to_number(to_char(current_date,'YYYY'),'9999')  --integer format


--to extract day and month from the current date

select extract (day from current_date)

--to get first and last day of the year:


select to_date((extract (year from current_date)) || '0101','YYYYMMDD')
select to_date((extract (year from current_date)) || '1231','YYYYMMDD')

--to get first of the month given a date

select date_trunc('month', current_timestamp)

--to get last month end date

select date_trunc('month', current_timestamp)-1


--to add 7 days to current date


select date(current_date +  cast('7 days' as interval))

--to get timestamp in a specific format

select to_timestamp( current_timestamp, 'YYYY-MM-DD HH24:MI:SS')
select to_timestamp( '2014-12-01 23:12:12', 'YYYY-MM-DD HH24:MI:SS')

--to add hours to a date

 select TO_CHAR(date((current_date +  cast('1 hour' as interval))),'YYYY-MM-DD') 

--To calculate difference in days , weeks between two dates

select datediff(week,'2012-01-01','2015-12-31') as numweeks;

select datediff(day,'2009-01-01','2015-12-31') as numdays;

Also check:
http://dwbitechguru.blogspot.ca/2014/09/jave-program-to-add-or-substract-dates.html

For loading and migration of data in  netezza, check:
http://dwbitechguru.blogspot.ca/2014/11/extract-load-migrate-filesdata-from.html

For SQL server date functions check:
http://dwbitechguru.blogspot.ca/2014/11/sql-server-important-date-manipulation.html

Monday, 14 July 2014

The power of IBM Netezza appliance

Netezza is a powerful data warehouse appliance that can handle gigabyte volume of data and used widely is many medium and large scale organizations. Some very interesting facts about Netezza is below:

Good stuff:
1) Netezza is indeed very powerful for OLAP and ETL purpose. The configuration I'm used to can handle queries on tables that have billions of records.  Netezza uses asymetric massive parallel processing and have multiple processing units to make query processing faster and run in parallel. Ofcourse, proper joins and distribution keys have to be set  when dealing with billions of records.


2) No tedious performance tuning required like in oracle or sql server. i.e. stuff like adding indexes, creating partitioning etc is not required. It allows adding primary keys but does not enforce that constrain and leaves it to the tools that loads data into netezza. Only distribution keys have to be set properly on the tables.

3) The above reduces the administration effort. Apparently, Netezza is promoted more like a no DBA tool. No software needs to be installed and comes installed with the netezza appliance.

4) Migration of data from one environment to another is very easy using tools such as nz_migrate, nz_sql, nzload.

5) NZ_Migrate is a handy tool to migrate bunch of tables  in one shot to another environment along with creation of the tables in the new environment. NZ_Migrate and NZ_UNLOAD are multi-threaded and can load /unload data using many threads.

6) Bulk loads are very fast. Netezza has its own Powerconnect driver to power these operations.

7) NA admin tool provides a good interface to administer the tool and as well see the resource availability and active/inactive queries.

Check also: Extract, Load, Migrate in Netezza:
http://dwbitechguru.blogspot.ca/2014/11/extract-load-migrate-filesdata-from.html

Some not so great stuff:

1) In earlier version, if we have to add a column then we have to drop a table and recreate it.

2) Same thing with views. We had to drop a view if the column data type changes in the base table.

3) It does not support sub queries in the select statement though this is not a big problem in ETL tools. Not sure if this is supported is latest versions.

4) How scalable is netezza? What to do when the volume of data or number of queries that need to run increase to a point where existing netezza appliance cannot support? This might mean buying more hardware to upgrade netezza. Compared to solutions like Hadoop or Amazon redshift, netezza might be not be very scalable.