| 37 | | # Declare our example executable code as Muldis DB ASTs. |
| 38 | | |
| 39 | | my $tynm_Text = ::Muldis::DB::Literal::EntityName.new( :text<sys.type.Text> ); |
| 40 | | my $tynm_UInt = ::Muldis::DB::Literal::EntityName.new( :text<sys.type.UInt> ); |
| 41 | | |
| 42 | | my $atnm_colour = ::Muldis::DB::Literal::EntityName.new( :text<colour> ); |
| 43 | | my $atnm_country = ::Muldis::DB::Literal::EntityName.new( :text<country> ); |
| 44 | | my $atnm_farm = ::Muldis::DB::Literal::EntityName.new( :text<farm> ); |
| 45 | | my $atnm_food = ::Muldis::DB::Literal::EntityName.new( :text<food> ); |
| 46 | | my $atnm_qty = ::Muldis::DB::Literal::EntityName.new( :text<qty> ); |
| 47 | | |
| 48 | | my $sca_type_Text = ::Muldis::DB::Literal::TypeInvo.new( :kind<Scalar>, :spec($tynm_Text) ); |
| 49 | | my $sca_type_UInt = ::Muldis::DB::Literal::TypeInvo.new( :kind<Scalar>, :spec($tynm_UInt) ); |
| 50 | | |
| 51 | | my $qrel_type_Relation = ::Muldis::DB::Literal::QuasiTypeInvo.new( :kind<Any>, :spec<Relation> ); |
| 52 | | |
| 53 | | my $heading_suppliers = ::Muldis::DB::Literal::TypeDict.new( :map([ |
| 54 | | [$atnm_farm, $sca_type_Text], |
| 55 | | [$atnm_country, $sca_type_Text], |
| 56 | | ]) ); |
| 57 | | my $heading_foods = ::Muldis::DB::Literal::TypeDict.new( :map([ |
| 58 | | [$atnm_food, $sca_type_Text], |
| 59 | | [$atnm_colour, $sca_type_Text], |
| 60 | | ]) ); |
| 61 | | my $heading_shipments = ::Muldis::DB::Literal::TypeDict.new( :map([ |
| 62 | | [$atnm_farm, $sca_type_Text], |
| 63 | | [$atnm_food, $sca_type_Text], |
| 64 | | [$atnm_qty, $sca_type_UInt], |
| 65 | | ]) ); |
| 66 | | my $heading_colours = ::Muldis::DB::Literal::TypeDict.new( :map([ |
| 67 | | [$atnm_colour, $sca_type_Text], |
| 68 | | ]) ); |
| 69 | | |
| 70 | | my $rel_type_suppliers = ::Muldis::DB::Literal::TypeInvo.new( |
| 71 | | :kind<Relation>, :spec($heading_suppliers) ); |
| 72 | | my $rel_type_foods = ::Muldis::DB::Literal::TypeInvo.new( |
| 73 | | :kind<Relation>, :spec($heading_foods) ); |
| 74 | | my $rel_type_shipments = ::Muldis::DB::Literal::TypeInvo.new( |
| 75 | | :kind<Relation>, :spec($heading_shipments) ); |
| 76 | | |
| 77 | | my $pnm_matched_suppl = ::Muldis::DB::Literal::EntityName.new( :text<matched_supp> ); |
| 78 | | my $pnm_desi_colour = ::Muldis::DB::Literal::EntityName.new( :text<desi_colour> ); |
| 79 | | my $pnm_src_suppl = ::Muldis::DB::Literal::EntityName.new( :text<src_suppl> ); |
| 80 | | my $pnm_src_foods = ::Muldis::DB::Literal::EntityName.new( :text<src_foods> ); |
| 81 | | my $pnm_src_shipm = ::Muldis::DB::Literal::EntityName.new( :text<src_shipm> ); |
| 82 | | |
| 83 | | my $opnm_rel_asn = ::Muldis::DB::Literal::EntityName.new( :text<sys.rtn.Relation.assign> ); |
| 84 | | my $opnm_rel_jn = ::Muldis::DB::Literal::EntityName.new( :text<sys.rtn.Relation.join> ); |
| 85 | | my $opnm_rel_sjn = ::Muldis::DB::Literal::EntityName.new( :text<sys.rtn.Relation.semijoin> ); |
| 86 | | |
| 87 | | my $anm_filter = ::Muldis::DB::Literal::EntityName.new( :text<filter> ); |
| 88 | | my $anm_source = ::Muldis::DB::Literal::EntityName.new( :text<source> ); |
| 89 | | my $anm_sources = ::Muldis::DB::Literal::EntityName.new( :text<sources> ); |
| 90 | | my $anm_target = ::Muldis::DB::Literal::EntityName.new( :text<target> ); |
| 91 | | my $anm_v = ::Muldis::DB::Literal::EntityName.new( :text<v> ); |
| 92 | | |
| 93 | | my $expr_3jn_ssp_sfd_scl = ::Muldis::DB::Literal::FuncInvo.new( |
| 94 | | :func($opnm_rel_jn), |
| 95 | | :ro_args(::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 96 | | [$anm_sources, newQuasiSet( |
| 97 | | :heading($qrel_type_Relation), |
| 98 | | :body([ |
| 99 | | ::Muldis::DB::Literal::VarInvo.new( :v($pnm_src_shipm) ), |
| 100 | | ::Muldis::DB::Literal::VarInvo.new( :v($pnm_src_foods) ), |
| 101 | | ::Muldis::DB::Literal::Relation.new( |
| 102 | | :heading($heading_colours), |
| 103 | | :body([ |
| 104 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 105 | | [$atnm_colour, ::Muldis::DB::Literal::VarInvo.new( |
| 106 | | :v($pnm_desi_colour) )], |
| 107 | | ]) ), |
| 108 | | ]), |
| 109 | | ), |
| 110 | | ]), |
| 111 | | )], |
| 112 | | ]) )), |
| 113 | | ); |
| 114 | | |
| 115 | | my $query_suppl_of_foods_of_clr = ::Muldis::DB::Literal::HostGateRtn.new( |
| 116 | | :upd_params(::Muldis::DB::Literal::TypeDict.new( :map([ |
| 117 | | [$pnm_matched_suppl, $rel_type_suppliers], |
| 118 | | ]) )), |
| 119 | | :ro_params(::Muldis::DB::Literal::TypeDict.new( :map([ |
| 120 | | [$pnm_desi_colour, $sca_type_Text], |
| 121 | | [$pnm_src_suppl, $rel_type_suppliers], |
| 122 | | [$pnm_src_foods, $rel_type_foods], |
| 123 | | [$pnm_src_shipm, $rel_type_shipments], |
| 124 | | ]) )), |
| 125 | | :vars(::Muldis::DB::Literal::TypeDict.new( :map([]) )), |
| 126 | | :stmts([ |
| 127 | | ::Muldis::DB::Literal::ProcInvo.new( |
| 128 | | :proc($opnm_rel_asn), |
| 129 | | :upd_args(::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 130 | | [$anm_target, ::Muldis::DB::Literal::VarInvo.new( :v($pnm_matched_suppl) )], |
| 131 | | ]) )), |
| 132 | | :ro_args(::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 133 | | [$anm_v, ::Muldis::DB::Literal::FuncInvo.new( |
| 134 | | :func($opnm_rel_sjn), |
| 135 | | :ro_args(::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 136 | | [$anm_source, ::Muldis::DB::Literal::VarInvo.new( |
| 137 | | :v($pnm_src_suppl) )], |
| 138 | | [$anm_filter, $expr_3jn_ssp_sfd_scl], |
| 139 | | ]) )), |
| 140 | | )], |
| 141 | | ]) )), |
| 142 | | ), |
| 143 | | ::Muldis::DB::Literal::ProcReturn.new(), |
| 144 | | ]), |
| 145 | | ); |
| 146 | | |
| 147 | | # Load our example executable code into the virtual machine. |
| 148 | | |
| 149 | | my $prep_rtn_suppl_of_foods_of_clr = $dbms.prepare( |
| 150 | | :rtn_ast($query_suppl_of_foods_of_clr) ); |
| 151 | | isa_ok( $prep_rtn_suppl_of_foods_of_clr, |
| 152 | | 'Muldis::DB::Interface::HostGateRtn' ); |
| 153 | | |
| 154 | | my $src_suppliers = $dbms.new_var( :decl_type($rel_type_suppliers) ); |
| 155 | | isa_ok( $src_suppliers, 'Muldis::DB::Interface::HostGateVar' ); |
| 156 | | my $src_foods = $dbms.new_var( :decl_type($rel_type_foods) ); |
| 157 | | isa_ok( $src_foods, 'Muldis::DB::Interface::HostGateVar' ); |
| 158 | | my $src_shipments = $dbms.new_var( :decl_type($rel_type_shipments) ); |
| 159 | | isa_ok( $src_shipments, 'Muldis::DB::Interface::HostGateVar' ); |
| 160 | | |
| 161 | | my $desi_colour = $dbms.new_var( :decl_type($sca_type_Text) ); |
| 162 | | isa_ok( $desi_colour, 'Muldis::DB::Interface::HostGateVar' ); |
| 163 | | |
| 164 | | my $matched_suppl = $dbms.new_var( :decl_type($rel_type_suppliers) ); |
| 165 | | isa_ok( $matched_suppl, 'Muldis::DB::Interface::HostGateVar' ); |
| 166 | | |
| 167 | | $prep_rtn_suppl_of_foods_of_clr.bind_host_params( |
| 168 | | :upd_args([ |
| 169 | | [$pnm_matched_suppl, $matched_suppl], |
| 170 | | ]), |
| 171 | | :ro_args([ |
| 172 | | [$pnm_desi_colour, $desi_colour], |
| 173 | | [$pnm_src_suppl, $src_suppliers], |
| 174 | | [$pnm_src_foods, $src_foods], |
| 175 | | [$pnm_src_shipm, $src_shipments], |
| 176 | | ]), |
| 177 | | ); |
| 178 | | |
| 179 | | # Declare our example literal source data sets as Muldis DB ASTs. |
| 180 | | |
| 181 | | my $rel_def_suppliers = ::Muldis::DB::Literal::Relation.new( |
| 182 | | :heading($heading_suppliers), |
| 183 | | :body([ |
| 184 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 185 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Hodgesons> )], |
| 186 | | [$atnm_country, ::Muldis::DB::Literal::Text.new( :v<Canada> )], |
| 187 | | ]) ), |
| 188 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 189 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Beckers> )], |
| 190 | | [$atnm_country, ::Muldis::DB::Literal::Text.new( :v<England> )], |
| 191 | | ]) ), |
| 192 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 193 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Wickets> )], |
| 194 | | [$atnm_country, ::Muldis::DB::Literal::Text.new( :v<Canada> )], |
| 195 | | ]) ), |
| 196 | | ]), |
| 197 | | ); |
| 198 | | |
| 199 | | my $rel_def_foods = ::Muldis::DB::Literal::Relation.new( |
| 200 | | :heading($heading_foods), |
| 201 | | :body([ |
| 202 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 203 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Bananas> )], |
| 204 | | [$atnm_colour, ::Muldis::DB::Literal::Text.new( :v<yellow> )], |
| 205 | | ]) ), |
| 206 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 207 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Carrots> )], |
| 208 | | [$atnm_colour, ::Muldis::DB::Literal::Text.new( :v<orange> )], |
| 209 | | ]) ), |
| 210 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 211 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Oranges> )], |
| 212 | | [$atnm_colour, ::Muldis::DB::Literal::Text.new( :v<orange> )], |
| 213 | | ]) ), |
| 214 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 215 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Kiwis> )], |
| 216 | | [$atnm_colour, ::Muldis::DB::Literal::Text.new( :v<green> )], |
| 217 | | ]) ), |
| 218 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 219 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Lemons> )], |
| 220 | | [$atnm_colour, ::Muldis::DB::Literal::Text.new( :v<yellow> )], |
| 221 | | ]) ), |
| 222 | | ]), |
| 223 | | ); |
| 224 | | |
| 225 | | my $rel_def_shipments = ::Muldis::DB::Literal::Relation.new( |
| 226 | | :heading($heading_shipments), |
| 227 | | :body([ |
| 228 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 229 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Hodgesons> )], |
| 230 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Kiwis> )], |
| 231 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(100) )], |
| 232 | | ]) ), |
| 233 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 234 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Hodgesons> )], |
| 235 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Lemons> )], |
| 236 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(130) )], |
| 237 | | ]) ), |
| 238 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 239 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Hodgesons> )], |
| 240 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Oranges> )], |
| 241 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(10) )], |
| 242 | | ]) ), |
| 243 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 244 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Hodgesons> )], |
| 245 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Carrots> )], |
| 246 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(50) )], |
| 247 | | ]) ), |
| 248 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 249 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Beckers> )], |
| 250 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Carrots> )], |
| 251 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(90) )], |
| 252 | | ]) ), |
| 253 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 254 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Beckers> )], |
| 255 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Bananas> )], |
| 256 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(120) )], |
| 257 | | ]) ), |
| 258 | | ::Muldis::DB::Literal::_ExprDict.new( :map([ |
| 259 | | [$atnm_farm, ::Muldis::DB::Literal::Text.new( :v<Wickets> )], |
| 260 | | [$atnm_food, ::Muldis::DB::Literal::Text.new( :v<Lemons> )], |
| 261 | | [$atnm_qty, ::Muldis::DB::Literal::Int.new( :v(30) )], |
| 262 | | ]) ), |
| 263 | | ]), |
| 264 | | ); |
| 265 | | |
| 266 | | # Load our example literal source data sets into the virtual machine. |
| 267 | | |
| 268 | | $src_suppliers.store_ast( :val_ast($rel_def_suppliers) ); |
| | 37 | # Declare our Perl-lexical variables to use for source data. |
| | 38 | |
| | 39 | my $src_suppliers |
| | 40 | = $dbms.new_var( :decl_type('sys.Core.Relation.Relation') ); |
| | 41 | isa_ok( $src_suppliers, 'Muldis::DB::Interface::Var' ); |
| | 42 | my $src_foods |
| | 43 | = $dbms.new_var( :decl_type('sys.Core.Relation.Relation') ); |
| | 44 | isa_ok( $src_foods, 'Muldis::DB::Interface::Var' ); |
| | 45 | my $src_shipments |
| | 46 | = $dbms.new_var( :decl_type('sys.Core.Relation.Relation') ); |
| | 47 | isa_ok( $src_shipments, 'Muldis::DB::Interface::Var' ); |
| | 48 | |
| | 49 | # Load our example literal source data sets into said Perl-lexicals. |
| | 50 | |
| | 51 | $src_suppliers.store_ast( |
| | 52 | :ast([ 'Relation', 'sys.Core.Relation.Relation', [ |
| | 53 | { |
| | 54 | 'farm' => [ 'NEText', 'Hodgesons' ], |
| | 55 | 'country' => [ 'NEText', 'Canada' ], |
| | 56 | }, |
| | 57 | { |
| | 58 | 'farm' => [ 'NEText', 'Beckers' ], |
| | 59 | 'country' => [ 'NEText', 'England' ], |
| | 60 | }, |
| | 61 | { |
| | 62 | 'farm' => [ 'NEText', 'Wickets' ], |
| | 63 | 'country' => [ 'NEText', 'Canada' ], |
| | 64 | }, |
| | 65 | ] ]), |
| | 66 | ); |