MINI MINI MANI MO
<?xml version="1.0"?>
<!--
Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
NAME
kuclzm.xsl
DESCRIPTION
XSLT stylesheet for XML => DDL conversion of CLustering and ZoneMap
clauses of tables
NOTES
Do NOT modify this file under any circumstance. Copy the file
if you wish to use this stylesheet with an external XML/XSL parser
MODIFIED MM/DD/YY
rapayne 07/21/15 - bug 1459344: new transform parameter to suppress
MATERIALIZED ZONEMAP clause from TABLE_T objects.
lbarton 10/27/11 - 36954_dpump_tabcluster_zonemap
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Top level imports -->
<xsl:import href="kucommon.xsl"/>
<!-- Top-level parameters -->
<xsl:param name="PRETTY">1</xsl:param>
<xsl:param name="SQLTERMINATOR">0</xsl:param>
<xsl:param name="EXPORT">0</xsl:param>
<xsl:param name="VERSION">9999999999</xsl:param>
<xsl:param name="MATERIALIZED_ZONEMAP">1</xsl:param>
<!-- params for parse -->
<xsl:param name="PRS_DDL">0</xsl:param>
<xsl:param name="PRS_DELIM">\{]`</xsl:param>
<xsl:param name="PRS_VERB">0</xsl:param>
<xsl:param name="PRS_OBJECT_TYPE">0</xsl:param>
<xsl:param name="PRS_SCHEMA">0</xsl:param>
<xsl:param name="PRS_NAME">0</xsl:param>
<xsl:param name="PRS_GRANTEE">0</xsl:param>
<xsl:param name="PRS_GRANTOR">0</xsl:param>
<xsl:param name="PRS_BASE_OBJECT_SCHEMA">0</xsl:param>
<xsl:param name="PRS_BASE_OBJECT_NAME">0</xsl:param>
<xsl:param name="PRS_BASE_OBJECT_TYPE">0</xsl:param>
<!-- Templates -->
<xsl:template match="CLST_T">
<!-- *******************************************************************
Template: CLST_T - top-level node for CLUSTERING object
******************************************************************** -->
<xsl:call-template name="DoParse">
<xsl:with-param name="Verb">ALTER</xsl:with-param>
<xsl:with-param name="ObjectType">TABLE</xsl:with-param>
<xsl:with-param name="SchemaNode" select="BASE_OBJ/OWNER_NAME"/>
<xsl:with-param name="NameNode" select="BASE_OBJ/NAME"/>
</xsl:call-template>
<xsl:text> ALTER TABLE </xsl:text>
<xsl:apply-templates select="BASE_OBJ"/>
<xsl:text>ADD</xsl:text>
<xsl:apply-templates select="CLST"/>
<xsl:if test="$SQLTERMINATOR=1">
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="CLST">
<!-- *******************************************************************
Template: CLST - clustering info
******************************************************************** -->
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:text> CLUSTERING </xsl:text>
<xsl:apply-templates select="CLSTJOIN"/>
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:text> BY </xsl:text>
<xsl:choose>
<xsl:when test="CLSTFUNC=1">INTERLEAVED </xsl:when>
<xsl:when test="CLSTFUNC=2">LINEAR </xsl:when>
</xsl:choose>
<xsl:text>ORDER </xsl:text>
<xsl:apply-templates select="CLSTCOLS"/>
<xsl:choose>
<xsl:when test="(FLAGS mod 2)>=1"> YES </xsl:when>
<xsl:otherwise> NO </xsl:otherwise>
</xsl:choose>
<xsl:text>ON LOAD </xsl:text>
<xsl:choose>
<xsl:when test="(FLAGS mod 4)>=2"> YES </xsl:when>
<xsl:otherwise> NO </xsl:otherwise>
</xsl:choose>
<xsl:text>ON DATA MOVEMENT </xsl:text>
<xsl:if test="$MATERIALIZED_ZONEMAP=1">
<xsl:call-template name="DoZonemap"/>
</xsl:if>
</xsl:template>
<xsl:template match="CLSTCOLS">
<!-- *******************************************************************
Template: CLSTCOLS - clustering columns
******************************************************************** -->
<xsl:variable name="MaxGroupid" select="CLSTCOLS_ITEM[position()=last()]/GROUPID"/>
<xsl:variable name="ThereAreGroups" select="$MaxGroupid != 0 and count(CLSTCOLS_ITEM)!=$MaxGroupid"/>
<xsl:for-each select="CLSTCOLS_ITEM">
<xsl:if test="position()=1">(</xsl:if>
<xsl:call-template name="GrpParen">
<xsl:with-param name="ThereAreGroups" select="$ThereAreGroups"/>
<xsl:with-param name="ListNode" select=".."/>
<xsl:with-param name="pos" select="position()"/>
<xsl:with-param name="pred" select="position()-1"/>
<xsl:with-param name="last" select="last()"/>
<xsl:with-param name="leftParen">1</xsl:with-param>
</xsl:call-template>
<xsl:apply-templates select="SCHEMA_OBJ">
<xsl:with-param name="TrailingBlank">0</xsl:with-param>
</xsl:apply-templates>
<xsl:text>."</xsl:text>
<xsl:value-of select="NAME"/>
<xsl:text>"</xsl:text>
<xsl:call-template name="GrpParen">
<xsl:with-param name="ThereAreGroups" select="$ThereAreGroups"/>
<xsl:with-param name="ListNode" select=".."/>
<xsl:with-param name="pos" select="position()"/>
<xsl:with-param name="suc" select="position()+1"/>
<xsl:with-param name="last" select="last()"/>
<xsl:with-param name="leftParen">0</xsl:with-param>
</xsl:call-template>
<xsl:choose>
<xsl:when test="position()=last()">)</xsl:when>
<xsl:otherwise>,</xsl:otherwise>
</xsl:choose>
<xsl:if test="$PRETTY=1">
<xsl:text>
 </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="GrpParen">
<xsl:param name="ThereAreGroups"/>
<xsl:param name="ListNode" select="''"/>
<xsl:param name="pos">0</xsl:param>
<xsl:param name="pred">0</xsl:param>
<xsl:param name="suc">0</xsl:param>
<xsl:param name="last">0</xsl:param>
<xsl:param name="leftParen">0</xsl:param>
<!-- *******************************************************************
Template: GrpParen - put right and left parens around groups
Parameters:
ThereAreGroups - TRUE = there are groups
ListNode - CLSTCOLS node
pos - value of position() for current CLSTCOLS_ITEM
pred - value of position() for prior CLSTCOLS_ITEM
suc - value of position() for next CLSTCOLS_ITEM
last - value of last()
leftParen - 1 = generate left paren if necessary
******************************************************************** -->
<xsl:if test="$ThereAreGroups">
<xsl:choose>
<xsl:when test="$leftParen=1">
<xsl:choose>
<xsl:when test="$pos=1">(</xsl:when>
<xsl:otherwise>
<xsl:variable name="grpid1" select="$ListNode/CLSTCOLS_ITEM[$pred]/GROUPID"/>
<xsl:variable name="grpid2" select="$ListNode/CLSTCOLS_ITEM[$pos]/GROUPID"/>
<xsl:if test="$grpid1 < $grpid2">(</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$pos=$last">)</xsl:when>
<xsl:otherwise>
<xsl:variable name="grpid1" select="$ListNode/CLSTCOLS_ITEM[$pos]/GROUPID"/>
<xsl:variable name="grpid2" select="$ListNode/CLSTCOLS_ITEM[$suc]/GROUPID"/>
<xsl:if test="$grpid1 < $grpid2">)</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="CLSTJOIN">
<!-- *******************************************************************
Template: CLSTJOIN - clustering on hierarchies
******************************************************************** -->
<xsl:for-each select="CLSTJOIN_ITEM">
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:if test="position()=1">
<xsl:call-template name="QuoteObject">
<xsl:with-param name="Schema" select="TAB1/OWNER_NAME"/>
<xsl:with-param name="Object" select="TAB1/NAME"/>
</xsl:call-template>
</xsl:if>
<xsl:text> JOIN </xsl:text>
<xsl:call-template name="QuoteObject">
<xsl:with-param name="Schema" select="TAB2/OWNER_NAME"/>
<xsl:with-param name="Object" select="TAB2/NAME"/>
</xsl:call-template>
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:text> ON (</xsl:text>
<xsl:call-template name="QuoteObject">
<xsl:with-param name="Schema" select="TAB1/OWNER_NAME"/>
<xsl:with-param name="Object" select="TAB1/NAME"/>
</xsl:call-template>
<xsl:text>."</xsl:text>
<xsl:value-of select="TAB1COL/NAME"/>
<xsl:text>"=</xsl:text>
<xsl:call-template name="QuoteObject">
<xsl:with-param name="Schema" select="TAB2/OWNER_NAME"/>
<xsl:with-param name="Object" select="TAB2/NAME"/>
</xsl:call-template>
<xsl:text>."</xsl:text>
<xsl:value-of select="TAB2COL/NAME"/>
<xsl:text>")</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template name="DoZonemap">
<!-- *******************************************************************
Template: DoZonemap -
WITH MATERIALIZED ZONEMAP ( name ) - no schema
or
WITHOUT MATERIALIZED ZONEMAP
******************************************************************** -->
<xsl:if test="$PRETTY=1">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="$EXPORT=1">
<xsl:text> WITHOUT MATERIALIZED ZONEMAP </xsl:text>
</xsl:when>
<xsl:when test="ZONEMAP and ZONEMAP/ZMNAME">
<xsl:text> WITH MATERIALIZED ZONEMAP ( </xsl:text>
<xsl:call-template name="QuoteObject">
<xsl:with-param name="Object" select="ZONEMAP/ZMNAME"/>
</xsl:call-template>
<xsl:text> )</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> WITHOUT MATERIALIZED ZONEMAP </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
OHA YOOOO