|
| 1 | +// Copyright 2024 Goldman Sachs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +###Relational |
| 16 | +Database demo::udtf::DemoDb |
| 17 | +( |
| 18 | + Schema Org |
| 19 | + ( |
| 20 | + Table Firm |
| 21 | + ( |
| 22 | + firmId INTEGER, |
| 23 | + legalname VARCHAR(200) |
| 24 | + ) |
| 25 | + TabularFunction Person |
| 26 | + ( |
| 27 | + firstname VARCHAR(200), |
| 28 | + lastname VARCHAR(200), |
| 29 | + age INTEGER, |
| 30 | + associatedFirmId INTEGER |
| 31 | + ) |
| 32 | + TabularFunction Person2 |
| 33 | + ( |
| 34 | + firstname VARCHAR(200), |
| 35 | + lastname VARCHAR(200), |
| 36 | + age INTEGER, |
| 37 | + associatedFirmId INTEGER |
| 38 | + ) |
| 39 | + TabularFunction ParentAndChildren |
| 40 | + ( |
| 41 | + firstname VARCHAR(200), |
| 42 | + lastname VARCHAR(200), |
| 43 | + id INTEGER, |
| 44 | + age INTEGER, |
| 45 | + parentId INTEGER |
| 46 | + ) |
| 47 | + ) |
| 48 | + |
| 49 | + Join firm_person(Org.Firm.firmId = Org.Person.associatedFirmId) |
| 50 | + Join firm_person2(Org.Firm.firmId = Org.Person2.associatedFirmId) |
| 51 | + Join relationship(Org.ParentAndChildren.parentId = {target}.id) |
| 52 | + |
| 53 | +) |
| 54 | + |
| 55 | + |
| 56 | +###Pure |
| 57 | +Class demo::udtf::Org::Firm |
| 58 | +{ |
| 59 | + firmId: Integer[1]; |
| 60 | + legalname: String[1]; |
| 61 | +} |
| 62 | + |
| 63 | +Class demo::udtf::Org::Person |
| 64 | +{ |
| 65 | + firstname: String[1]; |
| 66 | + lastname: String[1]; |
| 67 | + age: Integer[1]; |
| 68 | + associatedFirmId: Integer[1]; |
| 69 | + id: Integer[1]; |
| 70 | +} |
| 71 | + |
| 72 | +Association demo::udtf::Person_person |
| 73 | +{ |
| 74 | + parent: demo::udtf::Org::Person[1]; |
| 75 | + children: demo::udtf::Org::Person[1..*]; |
| 76 | +} |
| 77 | + |
| 78 | +Association demo::udtf::firm_person |
| 79 | +{ |
| 80 | + assoacitedFirm: demo::udtf::Org::Firm[1]; |
| 81 | + associatedPerson: demo::udtf::Org::Person[1..*]; |
| 82 | +} |
| 83 | + |
| 84 | +function demo::udtf::Org::FirmToPerson(): meta::pure::tds::TabularDataSet[1] |
| 85 | +{ |
| 86 | + demo::udtf::Org::Firm.all() |
| 87 | + ->project( |
| 88 | + [ |
| 89 | + x|$x.firmId, |
| 90 | + x|$x.associatedPerson.age |
| 91 | + ], |
| 92 | + [ |
| 93 | + 'Firm Id', |
| 94 | + 'Associated Person/Age' |
| 95 | + ] |
| 96 | + )->from( |
| 97 | + demo::udtf::DemoMapping, |
| 98 | + demo::runtimes::DemoRuntime |
| 99 | + ) |
| 100 | +} |
| 101 | + |
| 102 | +function demo::udtf::Org::FirmToPersonWithFilterOnPerson(): meta::pure::tds::TabularDataSet[1] |
| 103 | +{ |
| 104 | + demo::udtf::Org::Firm.all()->filter( |
| 105 | + x|$x.associatedPerson->exists( |
| 106 | + x_1|$x_1.firstname == 'David' |
| 107 | + ) |
| 108 | + )->project( |
| 109 | + [ |
| 110 | + x|$x.firmId, |
| 111 | + x|$x.associatedPerson.age |
| 112 | + ], |
| 113 | + [ |
| 114 | + 'Firm Id', |
| 115 | + 'Associated Person/Age' |
| 116 | + ] |
| 117 | + )->from( |
| 118 | + demo::udtf::DemoMapping, |
| 119 | + demo::runtimes::DemoRuntime |
| 120 | + ) |
| 121 | +} |
| 122 | + |
| 123 | +function demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion(): meta::pure::tds::TabularDataSet[1] |
| 124 | +{ |
| 125 | + demo::udtf::Org::Firm.all()->filter( |
| 126 | + x|$x.associatedPerson->exists( |
| 127 | + x_1|$x_1.firstname == 'David' |
| 128 | + ) |
| 129 | + )->project( |
| 130 | + [ |
| 131 | + x|$x.firmId, |
| 132 | + x|$x.associatedPerson.age |
| 133 | + ], |
| 134 | + [ |
| 135 | + 'Firm Id', |
| 136 | + 'Associated Person/Age' |
| 137 | + ] |
| 138 | + )->from( |
| 139 | + demo::udtf::DemoMappingUnion, |
| 140 | + demo::runtimes::DemoRuntime |
| 141 | + ) |
| 142 | +} |
| 143 | + |
| 144 | + |
| 145 | +function demo::udtf::Org::FetchChildrenViaSelfJoin(): meta::pure::tds::TabularDataSet[1] |
| 146 | +{ |
| 147 | + demo::udtf::Org::Person.all()->project( |
| 148 | + [ |
| 149 | + x|$x.firstname, |
| 150 | + x|$x.id, |
| 151 | + x|$x.children.age, |
| 152 | + x|$x.children.id, |
| 153 | + x|$x.children.firstname |
| 154 | + ], |
| 155 | + [ |
| 156 | + 'Firstname', |
| 157 | + 'Id', |
| 158 | + 'Children/Age', |
| 159 | + 'Children/Id', |
| 160 | + 'Children/Firstname' |
| 161 | + ] |
| 162 | + )->from( |
| 163 | + demo::udtf::DemoMappingSelfJoin, |
| 164 | + demo::runtimes::DemoRuntime |
| 165 | + ) |
| 166 | +} |
| 167 | + |
| 168 | + |
| 169 | +###Mapping |
| 170 | +Mapping demo::udtf::DemoMapping |
| 171 | +( |
| 172 | + *demo::udtf::Org::Firm[f]: Relational |
| 173 | + { |
| 174 | + ~primaryKey |
| 175 | + ( |
| 176 | + [demo::udtf::DemoDb]Org.Firm.firmId, |
| 177 | + [demo::udtf::DemoDb]Org.Firm.legalname |
| 178 | + ) |
| 179 | + ~mainTable [demo::udtf::DemoDb]Org.Firm |
| 180 | + firmId: [demo::udtf::DemoDb]Org.Firm.firmId, |
| 181 | + legalname: [demo::udtf::DemoDb]Org.Firm.legalname |
| 182 | + } |
| 183 | + *demo::udtf::Org::Person[p]: Relational |
| 184 | + { |
| 185 | + |
| 186 | + ~mainTable [demo::udtf::DemoDb]Org.Person |
| 187 | + firstname: [demo::udtf::DemoDb]Org.Person.firstname, |
| 188 | + lastname: [demo::udtf::DemoDb]Org.Person.lastname, |
| 189 | + age: [demo::udtf::DemoDb]Org.Person.age |
| 190 | + } |
| 191 | + |
| 192 | + demo::udtf::firm_person: Relational |
| 193 | + { |
| 194 | + AssociationMapping |
| 195 | + ( |
| 196 | + assoacitedFirm[p,f]: [demo::udtf::DemoDb]@firm_person, |
| 197 | + associatedPerson[f,p]: [demo::udtf::DemoDb]@firm_person |
| 198 | + ) |
| 199 | + } |
| 200 | +) |
| 201 | + |
| 202 | +###Mapping |
| 203 | +Mapping demo::udtf::DemoMappingUnion |
| 204 | +( |
| 205 | + *demo::udtf::Org::Person: Operation |
| 206 | + { |
| 207 | + meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_(p1,p2) |
| 208 | + } |
| 209 | + *demo::udtf::Org::Firm[f]: Relational |
| 210 | + { |
| 211 | + ~primaryKey |
| 212 | + ( |
| 213 | + [demo::udtf::DemoDb]Org.Firm.firmId, |
| 214 | + [demo::udtf::DemoDb]Org.Firm.legalname |
| 215 | + ) |
| 216 | + ~mainTable [demo::udtf::DemoDb]Org.Firm |
| 217 | + firmId: [demo::udtf::DemoDb]Org.Firm.firmId, |
| 218 | + legalname: [demo::udtf::DemoDb]Org.Firm.legalname |
| 219 | + } |
| 220 | + demo::udtf::Org::Person[p1]: Relational |
| 221 | + { |
| 222 | + ~mainTable [demo::udtf::DemoDb]Org.Person |
| 223 | + firstname: [demo::udtf::DemoDb]Org.Person.firstname, |
| 224 | + lastname: [demo::udtf::DemoDb]Org.Person.lastname, |
| 225 | + age: [demo::udtf::DemoDb]Org.Person.age |
| 226 | + } |
| 227 | + demo::udtf::Org::Person[p2]: Relational |
| 228 | + { |
| 229 | + ~mainTable [demo::udtf::DemoDb]Org.Person2 |
| 230 | + firstname: [demo::udtf::DemoDb]Org.Person2.firstname, |
| 231 | + lastname: [demo::udtf::DemoDb]Org.Person2.lastname, |
| 232 | + age: [demo::udtf::DemoDb]Org.Person2.age |
| 233 | + } |
| 234 | + |
| 235 | + demo::udtf::firm_person: Relational |
| 236 | + { |
| 237 | + AssociationMapping |
| 238 | + ( |
| 239 | + assoacitedFirm[p1,f]: [demo::udtf::DemoDb]@firm_person, |
| 240 | + assoacitedFirm[p2,f]: [demo::udtf::DemoDb]@firm_person2, |
| 241 | + associatedPerson[f,p1]: [demo::udtf::DemoDb]@firm_person, |
| 242 | + associatedPerson[f,p2]: [demo::udtf::DemoDb]@firm_person2 |
| 243 | + ) |
| 244 | + } |
| 245 | +) |
| 246 | + |
| 247 | +###Mapping |
| 248 | +Mapping demo::udtf::DemoMappingSelfJoin |
| 249 | +( |
| 250 | + *demo::udtf::Org::Person[p1]: Relational |
| 251 | + { |
| 252 | + ~primaryKey |
| 253 | + ( |
| 254 | + [demo::udtf::DemoDb]Org.ParentAndChildren.firstname |
| 255 | + ) |
| 256 | + ~mainTable [demo::udtf::DemoDb]Org.ParentAndChildren |
| 257 | + firstname: [demo::udtf::DemoDb]Org.ParentAndChildren.firstname, |
| 258 | + lastname: [demo::udtf::DemoDb]Org.ParentAndChildren.lastname, |
| 259 | + id: [demo::udtf::DemoDb]Org.ParentAndChildren.id, |
| 260 | + age: [demo::udtf::DemoDb]Org.ParentAndChildren.age |
| 261 | + } |
| 262 | + |
| 263 | + demo::udtf::Person_person: Relational |
| 264 | + { |
| 265 | + AssociationMapping |
| 266 | + ( |
| 267 | + children[p1,p1]: [demo::udtf::DemoDb]@relationship, |
| 268 | + parent[p1,p1]: [demo::udtf::DemoDb]@relationship |
| 269 | + ) |
| 270 | + } |
| 271 | +) |
| 272 | + |
| 273 | +###Connection |
| 274 | +RelationalDatabaseConnection demo::udtf::DemoSnowflakeConnection |
| 275 | +{ |
| 276 | + store: demo::udtf::DemoDb; |
| 277 | + type: Snowflake; |
| 278 | + specification: Snowflake |
| 279 | + { |
| 280 | + name: 'SUMMIT_MDM_DATA'; |
| 281 | + account: 'sfcedeawseast1d01'; |
| 282 | + warehouse: 'DEMO_WH'; |
| 283 | + region: 'us-east-1'; |
| 284 | + }; |
| 285 | + auth: SnowflakePublic |
| 286 | + { |
| 287 | + publicUserName: 'isThis'; |
| 288 | + privateKeyVaultReference: 'Hi'; |
| 289 | + passPhraseVaultReference: 'What'; |
| 290 | + }; |
| 291 | +} |
| 292 | + |
| 293 | + |
| 294 | +###Runtime |
| 295 | +Runtime demo::runtimes::DemoRuntime |
| 296 | +{ |
| 297 | + mappings: |
| 298 | + [ |
| 299 | + demo::udtf::DemoMapping |
| 300 | + ]; |
| 301 | + connections: |
| 302 | + [ |
| 303 | + demo::udtf::DemoDb: |
| 304 | + [ |
| 305 | + connection_2: demo::udtf::DemoSnowflakeConnection |
| 306 | + ] |
| 307 | + ]; |
| 308 | +} |
| 309 | + |
| 310 | +###Snowflake |
| 311 | +SnowflakeApp demo::udtf::snowflakeApp::App1 |
| 312 | +{ |
| 313 | + applicationName : 'App1_revised'; |
| 314 | + function : demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion():TabularDataSet[1]; |
| 315 | + ownership : Deployment { identifier: '441143'}; |
| 316 | + description : 'test App'; |
| 317 | + activationConfiguration : demo::udtf::DemoSnowflakeConnection; |
| 318 | +} |
0 commit comments