cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Power Designer: Cannot sort partition columns using scripting

0 Likes
688

Hi everyone!

We are trying to order the partitions of a table via scripting but we haven't succeeded yet. We found the problem when creating the record in the "Partitions" tab.

If we do it manually, the result is this:

However we don't know how to replicate that via scripting. Is it possible? Can anyone help us? At this moment this is our code:

Option Explicit

Dim mdl : set mdl = ActiveModel

Dim tbl, t , c ,objNewEC, objContent

dim havePartitions : havePartitions = false

set tbl = mdl.FindChildByCode("t_XXXXXXXXX",Cls_Table)

If tbl is nothing then

output "no se encontro la tabla"

Else

output "tbl.ExtendedCompositions.count=[" & tbl.ExtendedCompositions.count & "]"

If tbl.ExtendedCompositions.count > 0 then

set c = tbl.ExtendedCompositions.item(0)

output c.name

If strComp(c.name,"Partitions") = 0 then

havePartitions = true

End If

Else ' no hay ExtendedCompositions

havePartitions = false

output "Se crea la ExtendedCompositions para Partitions"

'set objNewEC = tbl.CreateObject(PdCommon.cls_ExtendedComposition)

set objNewEC = tbl.ExtendedCompositions.CreateNew

If not objNewEC is nothing then

objNewEC.name ="Partitions"

set objContent = objNewEC.Content.CreateNew

objContent.Name = "Partition_1"

objContent.Code = "Partition_1"

objContent.stereotype = "Partition"

Else

output "No se puede crear ExtendedCompositions"

End If

End If

End If ' si no encontro la tabla

With our code we only manage to create de partitions in the green part of the image but not the record in the partitions tab (red part of the image).

Thank you very much!!

View Entire Topic
Ondrej_Divis
Contributor

Hello Ire,

your procedure of initializing ExtendedComposition is not valid. Instead you can use my code below and see how it works on screenshot attached.

You have to initialize only compositions that don`t currently exist. If the Partitions composition already exists in your table, you will be able to find it using simple For each... cycle too.

Dim t, kolekce, ec, part

For each t in Activemodel.Tables
output "Compositions Count = " + CStr(t.ExtendedCompositions.Count)

output "creating composition"
'Set kolekce = t.GetCollectionByName("Partitions") ' this initializes the composition if it doesn`t already exist in the table

For each ec in t.ExtendedCompositions
output ec.Name
Set part = ec.content.CreateNewAt(0, PdCommon.cls_ExtendedSubObject) ' this will put new partition to the top of the list
'Set part = ec.content.CreateNew(PdCommon.cls_ExtendedSubObject) ' this will put new partition to the bottom of the list
part.stereotype = "Partition"
output part.name
Next
output "Compositions Count = " + CStr(t.ExtendedCompositions.Count)
Next

CreateNew or CreateNewAt methods could be used without any parameters when creating for example new column in a table. But when creating content of your "extended stuff", you have to specify objecttype (ExtendedSubObject) and don`t forget to specify Stereotype (Partition) too. See attached screenshot below.

HTH,

Ondrej Divis

P.S. Always add PD version to your questions. And in this particular case knowing which definition file you are using would be also useful. I used Hadoop Hive 2 for my screenshot-creating purposes.