1"use strict";(self.webpackChunk_elaraai_documentation_website=self.webpackChunk_elaraai_documentation_website||[]).push([[5477],{4875:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>p,frontMatter:()=>l,metadata:()=>a,toc:()=>d});var i=n(85893),o=n(11151),r=n(19676);const l={id:"05_select_a_collection",title:"Select a collection",tags:["learning"]},s="Select a collection",a={id:"transform_collection_data/05_select_a_collection",title:"Select a collection",description:"In this tutorial, you will use a row-based filter in tabular datastream. You will",source:"@site/docs/topics/03_work_with_data/06_transform_collection_data/05_select_a_collection.mdx",sourceDirName:"06_transform_collection_data",slug:"/transform_collection_data/05_select_a_collection",permalink:"/topics/03_work_with_data/transform_collection_data/05_select_a_collection",draft:!1,unlisted:!1,tags:[{label:"learning",permalink:"/topics/03_work_with_data/tags/learning"}],version:"current",sidebarPosition:5,frontMatter:{id:"05_select_a_collection",title:"Select a collection",tags:["learning"]},sidebar:"defaultSidebar",previous:{title:"Aggregate a collection",permalink:"/topics/03_work_with_data/transform_collection_data/04_aggregate_a_collection"},next:{title:"Disaggregate a collection field",permalink:"/topics/03_work_with_data/transform_collection_data/06_disaggregate_a_collection_field"}},c={},d=[{value:"Define and deploy a template",id:"define-and-deploy-a-template",level:2},{value:"Define a selection",id:"define-a-selection",level:2},{value:"Observe the selection",id:"observe-the-selection",level:2},{value:"Example solution",id:"example-solution",level:2}];function u(e){const t={code:"code",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h1,{id:"select-a-collection",children:"Select a collection"}),"\n",(0,i.jsx)(t.p,{children:"In this tutorial, you will use a row-based filter in tabular datastream. You will"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:["use the ",(0,i.jsx)(t.code,{children:"select()"})," method of ",(0,i.jsx)(t.code,{children:"PipelineBuilder()"})," to select certain values from a collection datastream, and"]}),"\n",(0,i.jsx)(t.li,{children:"launch a solution and observe the results."}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:["This lesson will assume that you have an empty project and asset which you can to deploy to a workspace named ",(0,i.jsx)(t.code,{children:"03_06_05_select_a_collection"})," with the following command:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"edk template deploy -ycw 03_06_05_select_a_collection\n"})}),"\n",(0,i.jsx)(t.h2,{id:"define-and-deploy-a-template",children:"Define and deploy a template"}),"\n",(0,i.jsxs)(t.p,{children:["To use the ",(0,i.jsx)(t.code,{children:"select()"})," method you will first perform the following steps:"]}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["define a datasource using a similar pattern as your previous ",(0,i.jsx)(t.code,{children:"My Source"})," definition."]}),"\n",(0,i.jsxs)(t.li,{children:["set the value of the datasource to be a ",(0,i.jsx)(t.code,{children:"Map<string, { value: bigint }>()"})," value."]}),"\n",(0,i.jsx)(t.li,{children:"add the datasource to a template"}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"In an asset, perform the above steps to create the resulting Typescript code:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",metastring:"showLineNumbers",children:'import { SourceBuilder, Template } from "@elaraai/core"\n\nconst my_source = new SourceBuilder("My Source")\n .value({\n value: new Map([\n ["0", { value: 0n }],\n ["1", { value: 15n }],\n ["2", { value: 25n }],\n ["3", { value: 55n }],\n ])\n })\n\nexport default Template(my_source) \n'})}),"\n",(0,i.jsx)(t.h2,{id:"define-a-selection",children:"Define a selection"}),"\n",(0,i.jsxs)(t.p,{children:["You can define a per-row selection to be output with the ",(0,i.jsx)(t.code,{children:"select()"})," method of ",(0,i.jsx)(t.code,{children:"PipelineBuilder()"}),", by taking the following steps:"]}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsx)(t.li,{children:'add a new pipeline "My Pipeline"'}),"\n",(0,i.jsxs)(t.li,{children:["add a ",(0,i.jsx)(t.code,{children:"select()"})," operation"]}),"\n",(0,i.jsxs)(t.li,{children:["define a single selection of ",(0,i.jsx)(t.code,{children:"description"})," based on ",(0,i.jsx)(t.code,{children:"value"})]}),"\n",(0,i.jsx)(t.li,{children:"add the new pipeline to the template"}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:["In the definition ",(0,i.jsx)(t.code,{children:"My Pipeline"})," add the above changes:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ts",metastring:"showLineNumbers {13-22}",children:'import { SourceBuilder, PipelineBuilder, Template, StringJoin } from "@elaraai/core"\n\nconst my_source = new SourceBuilder("My Source")\n .value({\n value: new Map([\n ["0", { value: 0n }],\n ["1", { value: 15n }],\n ["2", { value: 25n }],\n ["3", { value: 55n }],\n ])\n })\n\nconst my_pipeline = new PipelineBuilder("My Pipeline")\n .from(my_source.outputStream())\n .select({\n keep_all: false,\n selections: {\n description: fields => StringJoin`Got value ${fields.value}`\n }\n })\n\nexport default Template(my_source, my_pipeline);\n'})}),"\n",(0,i.jsx)(t.h2,{id:"observe-the-selection",children:"Observe the selection"}),"\n",(0,i.jsxs)(t.p,{children:["Once deployed, you can test your ",(0,i.jsx)(t.code,{children:"select()"})," by observing the value of the ",(0,i.jsx)(t.code,{children:"Pipeline.My Pipeline"})," datastream:"]}
1),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:'edk stream get "Pipeline.My Pipeline" -w 03_06_05_select_a_collection\n'})}),"\n",(0,i.jsx)(t.p,{children:"Which will result in the value below."}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:'\u25b9\u25b9\u25b9\u25b9\u25b9 Attempting to stream Pipeline.My Pipeline to stdout\n[{"key":"0","value":{"description":"Got value 0"}},\n{"key":"1","value":{"description":"Got value 15"}},\n{"key":"2","value":{"description":"Got value 25"}},\n{"key":"3","value":{"description":"Got value 55"}}]\n\u2714 Download complete\n'})}),"\n",(0,i.jsxs)(t.p,{children:["You can observe that the value of ",(0,i.jsx)(t.code,{children:"Pipeline.My Pipeline"})," now contains values including only the description."]}),"\n",(0,i.jsx)(t.h2,{id:"example-solution",children:"Example solution"}),"\n",(0,i.jsx)(t.p,{children:"The code for this tutorial is available below:"}),"\n",(0,i.jsx)(r.Z,{projectId:"elaraai/elara-documentation-projects/tree/main/03_work_with_data/06_transform_collection_data/05_select_a_collection",widgetEmbedOptions:{height:500,width:"100%",showSidebar:!0,view:"editor"}}),"\n",(0,i.jsx)(t.h1,{id:"next-steps",children:"Next steps"}),"\n",(0,i.jsxs)(t.p,{children:["In the next tutorial, you will use the ",(0,i.jsx)(t.code,{children:"disaggregate()"})," operation to 'unwrap' a child collection value from a collection datastream."]})]})}function p(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},19676:(e,t,n)=>{n.d(t,{Z:()=>D});var i=n(57747);const o=300,r="https://stackblitz.com",l=["angular-cli","create-react-app","html","javascript","node","polymer","typescript","vue"],s=["project","search","ports","settings"],a=["light","dark"],c=["editor","preview"],d={clickToLoad:e=>p("ctl",e),devToolsHeight:e=>h("devtoolsheight",e),forceEmbedLayout:e=>p("embed",e),hideDevTools:e=>p("hidedevtools",e),hideExplorer:e=>p("hideExplorer",e),hideNavigation:e=>p("hideNavigation",e),openFile:e=>f("file",e),showSidebar:e=>function(e,t){if("boolean"==typeof t)return`${e}=${t?"1":"0"}`;return""}("showSidebar",e),sidebarView:e=>m("sidebarView",e,s),startScript:e=>f("startScript",e),terminalHeight:e=>h("terminalHeight",e),theme:e=>m("theme",e,a),view:e=>m("view",e,c),zenMode:e=>p("zenMode",e)};function u(e={}){const t=Object.entries(e).map((([e,t])=>null!=t&&d.hasOwnProperty(e)?d[e](t):"")).filter(Boolean);return t.length?`?${t.join("&")}`:""}function p(e,t){return!0===t?`${e}=1`:""}function h(e,t){if("number"==typeof t&&!Number.isNaN(t)){const n=Math.min(100,Math.max(0,t));return`${e}=${encodeURIComponent(Math.round(n))}`}return""}function m(e,t="",n=[]){return n.includes(t)?`${e}=${encodeURIComponent(t)}`:""}function f(e,t){return(Array.isArray(t)?t:[t]).filter((e=>"string"==typeof e&&""!==e.trim())).map((t=>`${e}=${encodeURIComponent(t)}`)).join("&")}function _(){return Math.random().toString(36).slice(2,6)+Math.random().toString(36).slice(2,6)}function g(e,t){return`${y(t)}${e}${u(t)}`}function w(e,t){const n={forceEmbedLayout:!0};return t&&"object"==typeof t&&Object.assign(n,t),`${y(n)}${e}${u(n)}`}function y(e={}){return("string"==typeof e.origin?e.origin:r).replace(/\/$/,"")}function v(e,t,n){if(!t||!e||!e.parentNode)throw new Error("Invalid Element");e.id&&(t.id=e.id),e.className&&(t.className=e.className),function(e,t={}){const n=Object.hasOwnProperty.call(t,"height")?`${t.height}`:`${o}`,i=Object.hasOwnProperty.call(t,"width")?`${t.width}`:void 0;e.setAttribute("height",n),i?e.setAttribute("width",i):e.setAttribute("style","width:100%;")}(t,n),e.replaceWith(t)}function j(e){if("string"==typeof e){const t=document.getElementById(e);if(!t)throw new Error(`Could not find element with id '${e}'`);return t}if(e instanceof HTMLElement)return e;throw new Error(`Invalid element: ${e}`)}function b(e){return e&&!1===e.newWindow?"_self":"_blank"}class x{constructor(e){this.pending={},this.port=e,this.port.onmessage=this.messageListener.bind(this)}request({type:e,payload:t}){return new Promise(((n,i)=>{const o=_();this.pending[o]={resolve:n,reject:i},this.port.postMessage({type:e,payload:{...t,__reqid:o}})}))}messageListener(e){if("string"!=typeof e.data.payload?.__reqid)return;const{type:t,payload:n}=e.data,{__reqid:i,__success:o,__error:r}=n;this.pending[i]&&(o?this.pending[i].resolve(this.cleanResult(n)):this.pending[i].reject(r?`${t}: ${r}`:t),delete this.pending[i])}cleanResult(e){const t={...e};return delete t.__reqid,delete t.__success,delete t.__error,Object.keys(t).length?t:null}}class S{constructor(e,t){this.editor={openFile:e=>this._rdc.request({type:"SDK_OPEN_FILE",payload:{path:e}}),setCurrentFile:e=>this._rdc.request({type:"SDK_SET_CURRENT_FILE",payload:{path:e}}),setTheme:e=>this._rdc.request({type:"SDK_SET_UI_THEME",payload:{theme:e}}
1),setView:e=>this._rdc.request({type:"SDK_SET_UI_VIEW",payload:{view:e}}),showSidebar:(e=!0)=>this._rdc.request({type:"SDK_TOGGLE_SIDEBAR",payload:{visible:e}})},this.preview={origin:"",getUrl:()=>this._rdc.request({type:"SDK_GET_PREVIEW_URL",payload:{}}).then((e=>e?.url??null)),setUrl:(e="/")=>{if("string"!=typeof e||!e.startsWith("/"))throw new Error(`Invalid argument: expected a path starting with '/', got '${e}'`);return this._rdc.request({type:"SDK_SET_PREVIEW_URL",payload:{path:e}})}},this._rdc=new x(e),Object.defineProperty(this.preview,"origin",{value:"string"==typeof t.previewOrigin?t.previewOrigin:null,writable:!1})}applyFsDiff(e){const t=e=>null!==e&&"object"==typeof e;if(!t(e)||!t(e.create))throw new Error("Invalid diff object: expected diff.create to be an object.");if(!Array.isArray(e.destroy))throw new Error("Invalid diff object: expected diff.destroy to be an array.");return this._rdc.request({type:"SDK_APPLY_FS_DIFF",payload:e})}getDependencies(){return this._rdc.request({type:"SDK_GET_DEPS_SNAPSHOT",payload:{}})}getFsSnapshot(){return this._rdc.request({type:"SDK_GET_FS_SNAPSHOT",payload:{}})}}const E=[];class P{constructor(e){this.id=_(),this.element=e,this.pending=new Promise(((e,t)=>{const n=({data:t,ports:n})=>{"SDK_INIT_SUCCESS"===t?.action&&t.id===this.id&&(this.vm=new S(n[0],t.payload),e(this.vm),o())},i=()=>{this.element.contentWindow?.postMessage({action:"SDK_INIT",id:this.id},"*")};function o(){window.clearInterval(l),window.removeEventListener("message",n)}window.addEventListener("message",n),i();let r=0;const l=window.setInterval((()=>{if(this.vm)o();else{if(r>=20)return o(),t("Timeout: Unable to establish a connection with the StackBlitz VM"),void E.forEach(((e,t)=>{e.id===this.id&&E.splice(t,1)}));r++,i()}}),500)})),E.push(this)}}const I=e=>{const t=e instanceof Element?"element":"id";return E.find((n=>n[t]===e))??null};function $({template:e,title:t,description:n,dependencies:i,files:o,settings:r}){if(!l.includes(e)){const e=l.map((e=>`'${e}'`)).join(", ");console.warn(`Unsupported project.template: must be one of ${e}`)}const s=[],a=(e,t,n="")=>{s.push(function(e,t){const n=document.createElement("input");return n.type="hidden",n.name=e,n.value=t,n}(e,"string"==typeof t?t:n))};a("project[title]",t),"string"==typeof n&&n.length>0&&a("project[description]",n),a("project[template]",e,"javascript"),i&&("node"===e?console.warn("Invalid project.dependencies: dependencies must be provided as a 'package.json' file when using the 'node' template."):a("project[dependencies]",JSON.stringify(i))),r&&a("project[settings]",JSON.stringify(r)),Object.entries(o).forEach((([e,t])=>{a(`project[files][${function(e){return e.replace(/\[/g,"%5B").replace(/\]/g,"%5D")}(e)}]`,t)}));const c=document.createElement("form");return c.method="POST",c.setAttribute("style","display:none!important;"),c.append(...s),c}function k(e){if(!e?.contentWindow)return Promise.reject("Provided element is not an iframe.");return(I(e)??new P(e)).pending}const T={connect:k,embedGithubProject:function(e,t,n){const i=j(e),o=document.createElement("iframe");return o.src=w(`/github/${t}`,n),v(i,o,n),k(o)},embedProject:function(e,t,n){const i=j(e),o=function(e,t){const n=$(e);return n.action=w("/run",t),n.id="sb_run",`<!doctype html>\n<html>\n<head><title></title></head>\n<body>\n ${n.outerHTML}\n <script>document.getElementById('${n.id}').submit();<\/script>\n</body>\n</html>`}(t,n),r=document.createElement("iframe");return v(i,r,n),r.contentDocument?.write(o),k(r)},embedProjectId:function(e,t,n){const i=j(e),o=document.createElement("iframe");return o.src=w(`/edit/${t}`,n),v(i,o,n),k(o)},openGithubProject:function(e,t){const n=g(`/github/${e}`,t),i=b(t);window.open(n,i)},openProject:function(e,t){!function(e,t){const n=$(e);n.action=g("/run",t),n.target=b(t),document.body.appendChild(n),n.submit(),document.body.removeChild(n)}(e,t)},openProjectId:function(e,t){const n=g(`/edit/${e}`,t),i=b(t);window.open(n,i)}};var M=n(67294),N=n(85893);const D=e=>{const t=(0,M.useRef)(null),n=(0,M.useCallback)((async t=>{await T.embedGithubProject(t,e.projectId,{...e.widgetEmbedOptions,clickToLoad:!0})}),[]);return(0,M.useEffect)((()=>{null!=t?.current&&n(t.current)}),[t,n]),(0,N.jsx)(i.xu,{width:"100%",children:(0,N.jsx)("div",{ref:t})})}},57747:(e,t,n)=>
1{n.d(t,{Cd:()=>a,xu:()=>l});var i=n(16914),o=n(16554),r=n(85893),l=(0,i.m)("div");l.displayName="Box";var s=(0,o.G)((function(e,t){const{size:n,centerContent:i=!0,...o}=e,s=i?{display:"flex",alignItems:"center",justifyContent:"center"}:{};return(0,r.jsx)(l,{ref:t,boxSize:n,__css:{...s,flexShrink:0,flexGrow:0},...o})}));s.displayName="Square";var a=(0,o.G)((function(e,t){const{size:n,...i}=e;return(0,r.jsx)(s,{size:n,ref:t,borderRadius:"9999px",...i})}));a.displayName="Circle"},11151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>l});var i=n(67294);const o={},r=i.createContext(o);function l(e){const t=i.useContext(r);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:l(e.components),i.createElement(r.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.