Sunday, April 16, 2017

Performance improvement Tips using Hint in OBIEE 11g RPD or Other ways..

Performance improvement Tips using Hint in OBIEE 11g RPD or Other ways..

We can improve the performance of reports by doing tuning using Hint. This can be done by the following ways:

Tuning in RPD using Hint

Tuning in Report using Hint
In this article I will explain how to add Hint in RPD for tuning report performance.  Even also before using Hint either in RPD or report, we need to check whether the performance can be improved by developing proper inner versus outer joins, modeling efficient star schemas. Report performance tuning can trigger action across RPD, server and DB.

Hints allow us to change sub optimal SQL execution plans. They simply allow us to provide more information to the optimizer and influence the plan executed.


For slower performance of OBIEE Reports Hints are added in RPD to speed up the queries of those reports. In OBIEE we can add a database hint to a table object in the Physical layer, whenever this table is referenced in a query the hint will be applied. Importantly a hint should use the table alias whenever a query specifies an alias for a table, the table itself should not be used. Hints can be added by two ways:


Hints can be added in the Physical table itself

Or it can be added on the join of two tables in Physical Layer
Sometimes OBIEE report runs very slowly because of the main fact table holds huge volume data. So it takes some time to fetch data from the fact table for a specific period also. For this reason we need to use Hint in RPD in Physical Layer. There are multiple Hint functions available in database: Index, Hash, Parallel, Merge, Full.

Hint in RPD


Hint in Physical Object:


Open the RPD and check out the physical table where the Hint needs to be applied

Click on “General” tab of the table and apply the Hint
Here I am applying Parallel Hint in the table W_DAY_D.
Parallel Hint instructs the optimizer to use the specified number of concurrent servers for a parallel operation.
Syntax is:
/*+ PARALLEL (Table Name counter) */
Save the RPD and Run the report.

After adding the Hint in table “W_DAY_D” RPD will look like:




Hint in Joining Condition of Physical Objects:


We can Use USE_HASH function or PARALLEL function on the joining condition of fact (say W_GL_REVN_F) and Dimension (say W_GL_ACCOUNT_D).


Open the RPD and check out the physical join where the Hint needs to be applied

Double click on the joining condition and apply the Hint
Here I am applying Hash Hint in the joining condition between the tables Fact_W_GL_REVN_F and Dim_W_GL_ACCOUNT_D.
This USE_HASH hint instructs the optimizer to join each specified table with another row source using a hash join.
Syntax is:
/*+ USE_HASH (Table Name1 Table Name2 ) */


After adding the hints in Rpd it should look like:--




Performance improvement Tips :-

1. Use the log level judiciously. Switch it off for all users except Administrator. You can use the ‘Act as’ functionality to run the
request as a different user. Once you have authorized a user to act as a proxy user, he or she can then use the Settings > Act
As option in Oracle BI Presentation Services to select the target user to act as.

2. Use filter functions instead of case statements.

3. Avoid cast function.

4. Split huge dimensions.

5. Creating the Query Workload: This is a process of identifying the worst queries using either OBIEE’s log or database data
dictionary views like v$longops etc or using reports like AWR. Once the problematic queries are identified the SQL summary
advisor can be used to create materialized views which can have the most significant impact on the execution of these
problematic queries.

6. Populating Logical Level Counts Automatically: Rightclick
one or more business models and dimension objects, and choose
Estimate Levels. This helps OBIEE to gather some information that can help OBIEE to pick the most apt path which
answering queries related to hierarchies(or dimensions).

7. Intelligent join: Within a logical table source, the joins are always executed. When between logical tables, the joins are only
performed when required.
The tables snowflaked off the dimensions have parentchild
relationships with each other that mimic the dimensional
hierarchies.

8. Eliminate outer joins: Eliminating outer joins results in a more consistent record set, a simplified business model, and
improved performance. Make changes in the data model and change the ETL such that most of the joins in the BMM layer
are inner joins
Outer joins in logical table sources are always included in a query, even if the table source is not used. If possible, create one
logical table source without the outer join and another with the outer join. Order the logical table source with the outer join
after the nonouter
join so that it will be used only when necessary.

9. An opaque view (a physical layer table that consists of a Select statement) should be used only if there is no other solution.
Ideally, a physical table should be created, or alternatively a materialized view. A traditional database view is not needed
because it is identical to the opaque view.

10. OCI should be used for connecting to Oracle. Oracle Call Interface (OCI) applications can utilize client memory to take
advantage of the OCI result cache. A result cache stores the results of queries shared across all sessions. When these queries
are executed repeatedly, the results are retrieved directly from the cache memory, resulting in faster query response time. The
query results stored in the cache become invalid when data in the database objects being accessed by the query is modified.
The clientside
result cache is a separate feature from the serverside
result cache. Unlike the server result cache, the OCI
result cache does not cache results in the server/

11. Use Multithreaded Connections checkbox in the connection pool properties: When the check box is select ed, Oracle BI
Server terminates idle physical queries (threads). When not selected, one thread is tied to one database connection (number of
threads = maximum connections). Even if threads are idle, they consume memory.
The parameter DB_GATEWAY_THREAD_RANGE in the Server section of NQSConfig.ini establishes when Oracle BI Server
terminates idle threads. The lower number in the range is the number of threads that are kept open before Oracle BI Server
takes action. If the number of open threads exceeds the low point in the range, Oracle BI Server terminates idle threads. For
example, if DB_GATEWAY_THREAD_RANGE is set to 40200
and 75 threads are open, Oracle BI Server terminates any
idle threads.

12. Leading Hint: This helps you set the driving table in a join. This table will be accessed before any other table while executing
the join. Use this when you have an equijoin and one of the tables in the join has very few records compared to the other
tables. Ideally, in such a scenario, CBO should do nested loop join with the smaller table as the driving table. If this doesnot
happen then try the leading hint. Test the performance of the query before implementing it in the rpd
An almost similar technique is specifying the driving table in the joins in the BMM layer.
When you specify a driving table, the Oracle BI Server will use it if the query plan determines that its use will optimize query
processing. The small table (the driving table) is scanned, and parameterized queries are issued to the large table to select
matching rows. The other tables, including other driving tables, are then joined together.
In general, driving tables can be used with inner joins, and for outer joins when the driving table is the left table for a left outer
join, or the right table for a right outer join. Driving tables are not used for full outer joins.
MAX_PARAMETERS_PER_DRIVE_JOIN: This is a performance tuning parameter. In general, the larger its value, the fewer
parameterized queries will be generated. Values that are too large can result in parameterized queries that fail due to backend
database limitations. Setting the value to 0 (zero) turns off drive table joins.
MAX_QUERIES_PER_DRIVE_JOIN: This is used to prevent runaway drive table joins. If the number of parameterized
queries exceeds its value, the query is terminated and an error message is returned to the user.

13. Uncheck DISTINCT_SUPPORTED and ORDERBY_SUPPORTED check boxes from the database in the physical layer. Apply explicit ordering if required.

14. Don’t forget to mention the level of fact table sources, OBIEE picks tables to join based on this. logical dim sources should not be specified with level.

15. Push as much processing to the database as possible. This includes tasks such as filtering, string manipulation, and additive measures.

16. Feed cache for the broadest possible result. If you feed your cache for some aggregated result then it will be useful only for that result. So while making a plan to seed the cache, pick a report that has a more granular data to be displayed. If possible,
make reports that will exclusively be used for caching. The cached result of such reports should benefit other reports. These reports can then be scheduled to feed cache using ibots.

17. Use usage tracking to identify the candidates of aggregation.

18. Exchanging metadata with oracle database: By exchanging Oracle Business Intelligence metadata from the Oracle BI Server with your Oracle Database, you enable the database to accelerate the performance of data warehouse queries. You use the
Oracle BI Server utility sametaexport to exchange the metadata.
19. Have a data purging policy in place to remove unwanted data from the warehouse
20. Use star transformation.

21. Indexes and table partitioning are usually beneficial in datawarehouses. Make sure to avoid full table scans on tables that fetch 15% or less data of big tables. Small dimensions are better without index. Partitioning should be done wisely so that it helps most of your answers. Partitioning not only improves performance but also makes the data purging and data maintenance easier. Partitioning a global index allows partition pruning to take place within an index access, which results in reduced I/Os. By definition of good range or list partitioning, fast index scans of the correct index partitions can result in very
fast query times.
V$SQL_MONITOR and V$SQL_PLAN_MONITOR can help you do real time performance monitoring.

22. The SQL Performance Analyzer enables you to forecast the impact of system changes on SQL performance by testing these changes using a SQL workload on a test system.

23. SQL Plan management can be used for plan stability.

24. Use of the with clause – Check WITH_CLAUSE_SUPPORTED in database properties
It lets you reuse the same query block in a SELECT statement when it occurs more than once within a complex query. Oracle
Database retrieves the results of a query block and stores them in the user's temporary table space.

25. Database Resource Manager: The Database Resource Manager provides the ability to prioritize work within the Oraclesystem. Users with higher priority jobs get resources in order to minimize response time for online work, for example, while
users with lower priority jobs, such as batch jobs or reports, might encounter slower response times.
You can specify the maximum number of concurrently active sessions for each consumer group. When this limit is reached,
the Database Resource Manager queues all subsequent requests and runs them only after existing active sessions complete.

26. Using data compression: It reduces I/O. Both indexes and tables can be compressed. Check the trace to find out if high I/O
has been the reason for slow performance. If yes, compression can help. Compression can help improve performance for queries that scan large amounts of data, by reducing the amount of I/O required to scan that data.

27. The SQL Access Advisor is primarily responsible for making schema modification recommendations, such as adding or dropping indexes and materialized views. It also recommends a partitioning strategy. The SQL Tuning Advisor makes other
types of recommendations, such as creating SQL profiles and restructuring SQL statements. In some cases where significant performance improvements can be gained by creating a new index, the SQL Tuning Advisor may recommend doing so.
However, these recommendations must be verified by running the SQL Access Advisor with a SQL workload that contains a
set of representative SQL statements. In 11G, The SQL Access Advisor has been enhanced to include partition advice. It
recommends the right strategy to partition tables, indexes, and materialized views to get best performance from an application.
SQL tuning advisor can also be scheduled to get advisories

28. Using parallel hints for queries that involve large table scans, joins, or partitioned index scans. Parallelism might spoil
performance on over utilized systems or systems with small I/O bandwidth.

29. Use bitmap index for low cardinality columns. For example, on a column with one million rows, 10,000 distinct values.
Unlike most other types of indexes, bitmap indexes include rows that have NULL values. So queries with ‘is null’ will use
bitmap indexes. Do not use bitmap index in systems which have huge DML activity. Bitmap join index is also an interesting strategy.

30. Local indexes are better compared to global indexes for an OLAP system because search for data is at the partition level.

31.The size of the redo log files can influence performance, because the behavior of the database writer and archiver processes depend on the redo log sizes.

32.In case of nested loop joins it is very important to ensure that inner table is driven from (dependent on) the outer table. If the inner table's access path is independent of the outer table, then the same rows are retrieved for every iteration of the outer loop, degrading performance considerably. In such cases, hash joins joining the two independent row sources perform better.

Thanks

Location of the Startup folder in Windows 10/8


The Current Users Startup folder in Windows 10/8 is located at:

These programs start up for the current logged in user only. To directly access this folder, open Run, type shell:startup and hit Enter.

C:\ProgramData\Microsoft\Windows\Start Menu\Programs

Saturday, April 15, 2017

Checking Operation system certificate in obiee11g installation error


Checking Operation system certificate in obiee11g installation error






I faced the above issue while installing OBIEE11g in my local machine.

Issue:
OBIEE 11g 11.1.1.7.0 was recently certified on Windows Server 2012 64‑bit. When installing, the pre‑requisite check for the Operating
System fails.
Cause:
The software is certified; however, the Oracle Installer is not yet updated to reflect the certification. This can sometimes occur when a
certification happen post software release.

Resolution:
You can resolve this error by updating the pre‑requisite check file in the install media.
Step 1:
Navigate to where you have unzipped, with 7‑zip, the OBIEE 11g (11.1.1.7.0) installation media (locally or on a mount).
Step 2:
Backup the following file:
bishiphome\Disk1\stage\prereq\win64\refhost.xml
Step 3:
Update the refhost.xml file to add the new operating system at the end of the certified systems section




Step 4: Save the file
Step 5: Re‑start the Installer to re‑start and complete the install.
Step 6: The installer will then proceed without the error.

Thanks 

Friday, April 14, 2017

loopback adapter on windows 10

How to install Microsoft Loopback Adapter on Windows 10To install the microsoft loopback adapter on win 10 you must:

  1. right click on window start menu icon and select Device manager. Device manager window will immediatel open (or you may use any other way how to open device manager window)
  2. click on Action, and select Add legacy hardware
  3. click Next on welcome screen
  4. choose "Install the hardware that i manually select from a list" and click on Next
  5. scroll down and select Network adapters from offered common hardware types and click on Next
  6. select Microsoft as the manufacturer, and then select Microsoft KM-TEST Loopback adapter card model, click on Next
  7. click on Next
  8. click on Finish

OBIEE 11g Architecture

OBIEE 11g Architecture

At this high level, components in OBIEE 11g can be divided into two types:
  • Java Components, the parts of OBIEE that are written in J2EE and run directly in the application server. These components include BI Publisher, the BI Office plugin, the BI Security Service, BI SOA Services, BI Action Services and the JMX MBeans that are used for configuring OBIEE
  • System Components, which were implemented as Windows services in 10g, and include the BI Server, BI Presentation Server, BI Scheduler and BI Cluster Controller





Web Logic Server


This part of OBIEE system contains Admin Server and Managed Server. Admin server is responsible for managing the start and stop processes for Managed server. Managed Server comprises of BI Plugin, Security, Publisher, SOA, BI Office, etc.

Node Manager

Node Manager triggers the auto start, stop, restart activities and provides process management activities for Admin and Managed server.

Oracle Process Manager and Notification Server (OPMN)

OPMN is used to start and stop all components of BI system. It is managed and controlled by Fusion Middleware Controller.

Oracle BI System Components

These are non-Java components in an OBIEE system.

Oracle BI Server

This is the heart of Oracle BI system and is responsible for providing data and query access capabilities.

BI Presentation Server

It is responsible to present data from BI server to web clients which is requested by the end users.

Scheduler

This component provides scheduling capability in BI system and it has its own scheduler to schedule jobs in OBIEE system.

Oracle BI Java Host

This is responsible for enabling BI Presentation server to support various Java tasks for BI Scheduler, Publisher and graphs.

BI Cluster Controller

This is used for load balancing purposes to ensure that the load is evenly assigned to all BI server processes.


Tuesday, April 11, 2017

File Locations in OBIEE 11G

File Locations in OBIEE 11G


Start BI Services (parameter:  start_all)
..\\\instances\instance1\bifoundation\OracleBIApplication\coreapplication\StartStopServices.cmd start_all

Stop BI Services (parameter:  stop_all)
..\\\instances\instance1\bifoundation\OracleBIApplication\coreapplication\StartStopServices.cmd stop_all

Sample Application Data and Repository
..\\\instances\instance1\bifoundation\OracleBIServerComponent\coreapplication_obis1\sample

BI Repository(RPD)
..\\\instances\instance1\bifoundation\OracleBIServerComponent\coreapplication_obis1\repository

Usage tracking and Marketing Segmentation Scripts
..\\\instances\instance1\bifoundation\OracleBIServerComponent\coreapplication_obis1\schema

BI Server Cache file
..\\\instances\instance1\bifoundation\OracleBIServerComponent\coreapplication_obis1\cache

BI Presentation Catalog
..\\\instances\instance1\bifoundation\OracleBIPresentationServicesComponent\coreapplication_obips1\catalog

Clustered Component
..\\\instances\instance1\bifoundation\OracleBIClusterControllerComponent\coreapplication_obiccs1

Scheduler Components (Scheduler schema etc.)
..\\\instances\instance1\bifoundation\OracleBISchedulerComponent\coreapplication_obisch1

BI ODBC , Javahost and other components
..\\\instances\instance1\bifoundation

Start Weblogic Server (startWebLogic.cmd)
..\\\user_projects\domains\bifoundation_domain

BI Config Files
..\\\instances\instance1\config

Repository Config files (NQSConfig.INI,DBFeatures.INI etc)
..\\\instances\instance1\config\OracleBIServerComponent\coreapplication_obis1

Catalog config files(instanceconfig.xml,credentialstore.xml etc)
..\\\instances\instance1\config\OracleBIPresentationServicesComponent\coreapplication_obips1

Scheduler Catalog config files (instanceconfig.xml)
..\\\instances\instance1\config\OracleBISchedulerComponent\coreapplication_obisch1

Cluster Config files
..\\\instances\instance1\config\OracleBIApplication\coreapplication

OPMN Startup (parameter:  startall)
..\\\instances\instance1\bin opmnctl startall

OPMN Stop (parameter:  stopall)
..\\\instances\instance1\bin opmnctl stopall

BI PATH Initialisation
..\\\instances\instance1\bifoundation\OracleBIApplication\coreapplication\setup\bi-init.cmd

Weblogic Admin and Managed Server start/stop scripts(startWebLogic.cmd,startManagedWebLogic.cmd etc.)
..\\\user_projects\domains\bifoundation_domain\bin

BIPublisher repository and Config files
..\\\user_projects\domains\bifoundation_domain\config\bipublisher

FMW Security Config files (system-jazn-data.xml)
..\\\user_projects\domains\bifoundation_domain\config\fmwconfig

BI Components Log files
..\\\instances\instance1\diagnostics\logs

BI Server Log files (NQserver.log , NQQuery.log etc.)
..\\\instances\instance1\diagnostics\logs\OracleBIServerComponent\coreapplication_obis1

BI Presentation Server Log files (sawlog)
..\\\instances\instance1\diagnostics\logs\OracleBIPresentationServicesComponent\coreapplication_obips1

Installation Log files
..\\\logs

Date Calculation Formulas OBIEE

Date Calculation Formulas

In OBIEE, we cannot perform an arithmetic operation on a DATE or TIMESTAMP. These are considered Non-numeric types.
To calculate difference between two dates, OBIEE provides a TIMESTAMPDIFF function. The syntax for using the function is:
TIMESTAMPDIFF(interval, first_date, second_date)
First_date and second_date have to be valid values in the TIMESTAMP type. Interval is a specified value.  Valid values for INTERVAL are:
  • SQL_TSI_SECOND
  • SQL_TSI_MINUTE
  • SQL_TSI_HOUR
  • SQL_TSI_DAY
  • SQL_TSI_WEEK
  • SQL_TSI_MONTH
  • SQL_TSI_QUARTER
  • SQL_TSI_YEAR
If the dates are not in a valid TIMESTAMP format, use CAST function to convert values into TIMESTAMP type. See example below:
TIMESTAMPDIFF(SQL_TSI_DAY, CAST(VALUEOF("MY_DATE_COLUMN") as TIMESTAMP), CURRENT_DATE)

1)    First Day of the Previous Year
-------------------------------------------
TIMESTAMPADD( SQL_TSI_YEAR , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) 


From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD removes a year from the returned date for the First Day of the Previous Year

2) First Day of the Current Year
----------------------------------
TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE) 


This calculation returns the first day of the year by deducting one less than the total number of days in the year.

3) First Day of the Next Year
---------------------------------------
TIMESTAMPADD( SQL_TSI_YEAR , 1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE))
From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD adds a year to the date returned which will give the first day of the next year.

4) First Day of the Previous Month
-----------------------------------
TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))


 From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD then subtracts one month from the first day of the Current Month arriving to the First Day of the previous month.

5) First Day of the Current Month
--------------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE) This expression gets the current day of the month and subtracts one less than the current day to arrive at the first day of the month.

6) First Day of the Next Month
-------------------------------------
TIMESTAMPADD(SQL_TSI_MONTH, 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) 


From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD then adds one month from the first day of the Current Month arriving to the First Day of the next month.

7) First Day of Current Quarter
---------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , DAY_OF_QUARTER( CURRENT_DATE) * -(1) + 1, CURRENT_DATE) 


This was included to show the calculations discussed above can be used with other functions. This is the same expression as the one that returns the first day of the current month except this one uses the DAY_OF_QUARTER property to return the first day of the current quarter.

8) Last Day of the Previous Month
--------------------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) 


From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD subtracts a month to arrive at the first day of the previous month.

9) Last Day of Current Month
---------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) 


From right to left the first TIMESTAMPADD finds the first day of the current Month. The second TIMESTAMPADD adds one month to the date to arrive at the first day of the next month. The final TIMESTAMPADD subtracts one day from the returned date to arrive at the last day of the Current Month.

10) Last Day of the Next Month
-----------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) 


From right to left the first TIMESTAMPADD finds the first day of the current Month. The second TIMESTAMPADD adds two months to the date to arrive at the first day of month after next. The final TIMESTAMPADD subtracts one day from the returned date to arrive at the last day of the Next Month.

11) Last Day of Previous Year
------------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1,
CURRENT_DATE)) 


From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD subtracts one day to arrive at December 31st of the previous year.

12) Last Day of Current Year
------------------------------------------
TIMESTAMPADD(SQL_TSI_YEAR, 1, TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) 


From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD deducts one day to arrive at December 31 of the previous year. The third TIMESTAMPADD adds a single year to the date to arrive at December 31 of the Current Year.

13) Last Day of the Next Year
----------------------------------------
TIMESTAMPADD(SQL_TSI_YEAR, 2, TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) 


From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD deducts one day to arrive at December 31 of the previous year. The third TIMESTAMPADD adds 2 years to the date to arrive at December 31 of the Next Year.

14) Last Day of Current Quarter
--------------------------------------------
TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_QUARTER , 1, TIMESTAMPADD( SQL_TSI_DAY , DAY_OF_QUARTER( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) 


Demonstrated using Quarters. From right to left the first TIMESTAMPADD returns the first day of the Current Quarter. The second TIMESTAMPADD returns the first day of the next quarter. The final TIMESTAMPADD subtracts a single day from the date to arrive at the last day of the Current Quarter.

15) Number of days between First Day of Year and Last Day of Current Month
------------------------------------------------------------------------------------------------------------------
 TIMESTAMPDIFF(SQL_TSI_DAY, CAST('2010/01/01 00:00:00' AS DATE), TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)))) 


For simplicity I hard coded the January 1, 2010 date and CAST it to a date. I could have used the First Day of the Current Year calculation but didn’t want to over clutter the example. The second part of the TIMESTAMPDIFF uses Last Day of the Current Month calculation to force the TIMESTAMPDIFF to calculate the number of days between the first day of the year and the last day of the current month.
16) Lat Date of Week:

TIMESTAMPADD(SQL_TSI_DAY,DAYOFWEEK(Current_Date)*-1,TIMESTAMPADD(SQL_TSI_WEEK, 1, Current_date))


17) First Date of Year:

TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)

18) Last Date of Year:

TIMESTAMPADD(SQL_TSI_YEAR, 1, TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)))

 BEST PYSPARK LEARNING SITES https://www.youtube.com/watch?v=s3B8HXLlLTM&list=PL2IsFZBGM_IHCl9zhRVC1EXTomkEp_1zm&index=5 https://www...