This may apply to Athena and or prestodb in general array empty? Per stackoverflow learned the name for this in the docs is cardinality select cardinality(array[]) = 0; This cannot be applied to the output of a json_extract(json_parse(data), '$.blah.flah.clah') since cardinality() takes ARRAY and not JSON. However, that JSON can be cast. For example, if '$.blah.flah.clah' is like [{"hi": "there"}, {"so": "then"}], then this cardinality(cast(json_extract(json_parse(what), '$.blah.flah.clah') as array(map(varchar, varchar)))) will produce the length of those arrays....

(updated February 26, 2023) · 1 min · 76 words · Michal Piekarczyk

Make a zip file for a lambda layer From a well written reference here : adjust the python version as needed #!/bin/bash echo -e "blah-lib==2.0\n\ umm-lib==0.45" > requirements.txt export LIB_DIR="python" rm -rf ${LIB_DIR} && mkdir -p ${LIB_DIR} docker run --rm -v $(pwd):/foo -w /foo lambci/lambda:build-python3.8 \ pip install -r requirements.txt -t ${LIB_DIR} zip -r layer.zip python And I like to use vim layer.zip to look at the contents Get lambda configuration details by boto Super handy client = boto3....

(updated February 26, 2023) · 1 min · 113 words · Michal Piekarczyk

State Machine life cycle Adapting this from my stackoverflow answer to a question on updating state machines in step functions step_function_stack.yaml AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' Description: >- A description of the State Machine goes here. Resources: MyStateMachineName: Type: AWS::StepFunctions::StateMachine Properties: RoleArn: "arn:aws:iam::{{aws_account_id}}:role/service-role/StepFunctions-MyStepFunctionRole" StateMachineName: "MyStateMachineName" StateMachineType: "EXPRESS" DefinitionString: Fn::Sub: | {{full_json_definition}} manage_step_functions.py import boto3 import os import time from jinja2 import Environment def do_render(full_json_definition): with open('step_function_stack.yaml') as fd: template = fd.read() yaml = Environment()....

(updated February 26, 2023) · 3 min · 462 words · Michal Piekarczyk

I Stumbled on this gem of a stack overflow answer ( in here ) , which goes into some great detail but one of the hacks I learned is you can modify IFS to change the following behavior. (For context, I have some files with spaces in the names and they end in RR.jpg . $ for file in $(ls *RR.jpg) ; do echo $file ; done 2021-05-19 09.01.51RR.jpg 2021-05-19 09....

(updated February 26, 2023) · 1 min · 118 words · Michal Piekarczyk

atom vec [] and while loop… (let [results-atom (atom [])] ; ; (println "elements: " (count @results-atom)) ; (swap! results-atom conj "hi") ;results-atom (while (< (count @results-atom) 3) (do (println "doing") ; insert (swap! results-atom conj "hi") (println "elements: " (count @results-atom)) )) ; done (println "Done. Now have elements: " (count @results-atom)) ) => doing elements: 1 doing elements: 2 doing elements: 3 Done. Now have elements: 3 nil

(updated February 26, 2023) · 1 min · 70 words · Michal Piekarczyk