Nouvelle publication

Rechercher

Article
· Mai 4, 2024 3m de lecture

Using VECTORs in ObjectScript

Most examples I've seen so far in OEX or DC left the impression that VECTORs
are just something available with SQL with the 3 Functions especially around VECTOR_Search.
* TO_VECTOR()
* VECTOR_DOT_PRODUCT ()
* VECTOR_COSINE ()

There is a very useful summary hidden in iris-vector-search demo package.
From there you find everything you need over several links and corners.

I was missing more VECTOR methods and placed a related request in Idea Portal

Next I remembered that every SQL Method  or procedure lives on a bunch of ObjectScript code
So I went to search for it an this is the summary of the research.

%Library.Vector is the core description of the new DataType
It's a complex structure like Objects or %DynamicObjects or $Bit Expressions that require specific access methods
We also see 2 required parameters: 
* DATATTYPE  - once set can't be changed.
  Accepted types:  "integer" (or "int"), "double", "decimal", "string", and "timestamp".
* LEN  >0 , may grow bur never shrink

$vector() / $ve()  is the basic method for Vector access
Assign Vector Data  >>>  SET $VE(. . .) = val
Return Vector Data  >>>  WRITE $VE(. . .) ,  SET var=$VE(. . .) 
  HINT: a single position returns the value, but position from::to returns another Vector !
Delete Vector Data  >>>  KILL $VE(. . .) 
All 3 require at least 1 Position parameter. You may understand this as dimensions.

$isvector() the obvious check for correct format before jumping into operations. 

$vectorop() / $vop() covers all other functions related to vectors
The call parameters are typically (operation, vector)
Some operations offer an optional bitexpr. It marks positions/dimensions to be ex-/in-cluded.
Example: 
- Think of a 3D vector. you just want to operate on x - and y axis and not to z 

Single Vector Operations

Aggregate Operations
 * "count"
 * "max"
 * "min"
 * "sum"
Filter Operations
 * "defined"
 * "undefined"
 * "<"
 * "<="
 * ">"
 * ">="
 * "="
 * "!="
 * "between"
Numeric Operations
 * "+"
 * "-"
 * "/"
 * "*"
 * "**"
 * "#"
 * "e-"
 * "e/"
 * "ceiling"
 * "floor"
String Operations
 * "_"
 * "e_"
 * "lower"
 * "upper"
 * "substring"
 * "trim"
 * "triml"
 * "trimr"
Grouping Operations
 * "group"
 * "countgb"
Miscellaneous Operations
 * "convert"
 * "length"
 * "mask"
 * "positions"
 * "set"
Informative Operations
 * "bytesize"
 * "type"

Multi Vector Operations  (mostly 2 vectors)

Vector-wise Filter Operations
 * "v<"
 * "v<="
 * "v>"
 * "v>="
 * "v="
 * "v!="
Vector-wise Arithmetic Operations
 * "v+"
 * "v-"
 * "v/"
 * "v*"
 * "v**"
 * "v#"
Vector Concatenation
 * "v_"
Vector Grouping
 * "countg"
 * "maxg"
 * "ming"
 * "sumg"
Vector Merge
 * "vset"

You see there is a rich set of tools already available.
If you study docs in details, the purpose or advantage of the results may
not be evident immediately. 

Though I hope you got an overview of what is available now.

1 Comment
Discussion (1)1
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Mai 4, 2024

Abierto el plazo de inscripción para el InterSystems Global Summit 2024

Hola comunidad,

Nos complace anunciar que ya está abierto el plazo de inscripción para el evento del año: la Cumbre Mundial InterSystems 2024.

➡️ InterSystems Global Summit 2024

🗓 Fechas: 9-12 junio, 2024

📍 Ubicación: Gaylord National Harbor Resort and Convention Center, National Harbor, MD, EE.UU

InterSystems Global Summit es el principal evento para la comunidad tecnológica de InterSystems, una reunión de líderes y desarrolladores de la industria a la vanguardia de sus respectivos sectores. Este evento atrae a una amplia gama de asistentes, desde ejecutivos de nivel C, expertos en la materia y líderes visionarios, gerentes, directores y desarrolladores. Los asistentes se reúnen para establecer contactos con sus homólogos, conectar con los socios de InterSystems, aprender las mejores prácticas y conocer de primera mano las próximas funciones y futuras innovaciones de InterSystems.

¡Esperamos veros en el InterSystems Global Summit 2024!

1 Comment
Discussion (1)2
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Mai 4, 2024

Top Videos for InterSystems Developers in April 2024

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Article
· Mai 3, 2024 6m de lecture

Demo: Connecting Locally to an S3 Bucket without an AWS Account

Introduction

Accessing Amazon S3 (Simple Storage Service) buckets programmatically is a common requirement for many applications. However, setting up and managing AWS accounts is daunting and expensive, especially for small-scale projects or local development environments. In this article, we'll explore how to overcome this hurdle by using Localstack to simulate AWS services. Localstack mimics most AWS services, meaning one can develop and test applications without incurring any costs or relying on an internet connection, which can be incredibly useful for rapid development and debugging. We used ObjectScript with embedded Python to communicate with Intersystems IRIS and AWS simultaneously. Before beginning, ensure you have Python and Docker installed on your system. When Localstack is set up and running, the bucket can be created and used. 

Creating an S3 Bucket from ObjectScript with Embedded Python

Now that LocalStack is running, let's create an S3 bucket programmatically. We'll use Python and the Boto3 library - a Python SDK for AWS services. Take a look at the MakeBucket method provided in the S3UUtil class. This method utilizes Boto3 to create an S3 bucket:

ClassMethod MakeBucket(inboundfromiris As %String) As %Status [ Language = python ]

{

    import boto3

    s3 = boto3.client(

        service_name='s3', 

        region_name="us-east-1", 

        endpoint_url='http://host.docker.internal:4566', 
    )

    try:

        s3.create_bucket(Bucket=inboundfromiris)

        print("Bucket created successfully")

        return 1
    except Exception as e:

        print("Error:", e)

        return 0
}

To create a bucket, you would call this method with the desired bucket name:

status = S3UUtil.MakeBucket("mybucket")

Uploading Objects to the Bucket from ObjectScript with Embedded Python

Once the bucket is created, you can upload objects to it programmatically. The PutObject method demonstrates how to achieve this:

ClassMethod PutObject(inboundfromiris As %String, objectKey As %String) As %Status [ Language = python ]

{

    import boto3

    try:

        content = "Hello, World!".encode('utf-8')

        s3 = boto3.client(

            service_name='s3',

            region_name="us-east-1",

            endpoint_url='http://host.docker.internal:4566'
        )

        s3.put_object(Bucket=inboundfromiris, Key=objectKey, Body=content)

        print("Object uploaded successfully!")

        return 1
    except Exception as e:

        print("Error:", e)

        return 0
}

Call this method to upload an object:

Do ##class(S3.S3UUtil).PutObject("inboundfromiris", "hello-world-test")

 

Listing Objects in the Bucket from ObjectScript with Embedded Python

To list objects in the bucket, you can use the FetchBucket method:

ClassMethod FetchBucket(inboundfromiris As %String) As %Status [ Language = python ]

{

    import boto3

    s3 = boto3.client(

        service_name='s3', 

        region_name="us-east-1", 

        endpoint_url='http://host.docker.internal:4566', 
    )

    try:

        response = s3.list_objects(Bucket=inboundfromiris)

        if 'Contents' in response:

            print("Objects in bucket", inboundfromiris)

            for obj in response['Contents']:

                print(obj['Key'])

            return 1
        else:

            print("Error: Bucket is empty or does not exist")

            return 0
    except Exception as e:

        print("Error:", e)

        return 0
}

Call the FetchBucket method to list objects from the bucket:

do ##class(S3.S3UUtil).FetchBucket("inboundfromiris")


 

Retrieving Objects from the Bucket from ObjectScript with Embedded Python

Finally, to retrieve objects from the bucket, you can use the PullObjectFromBucket method:

ClassMethod PullObjectFromBucket(inboundfromiris As %String, objectKey As %String) As %Status [ Language = python ]

{

    import boto3

    def pull_object_from_bucket(bucket_name, object_key):

        try:

            s3 = boto3.client(

                service_name='s3', 

                region_name="us-east-1", 

                endpoint_url='http://host.docker.internal:4566', 
            )

            obj_response = s3.get_object(Bucket=bucket_name, Key=object_key)

            content = obj_response['Body'].read().decode('utf-8')

            print("Content of object with key '", object_key, "':", content)

            return True

        except Exception as e:

            print("Error:", e)

            return False

    pull_object_from_bucket(inboundfromiris, objectKey)

}

Call this method:

Do ##class(DQS.CloudUtils.S3.S3UUtil).PullObjectFromBucket("inboundfromiris", "hello-world-test")

 

The discussion here is just the beginning, as it's clear there's plenty more ground to cover. I invite readers to dive deeper into this subject and share their insights. Let's keep the conversation going and continue advancing our understanding of this topic.

I'm eager to hear thoughts and contributions.

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Mai 3, 2024

[Video] Understanding HL7 FHIR Profiles

Hey Developers,

Watch the latest video on InterSystems Developers YouTube:

⏯ Understanding HL7 FHIR Profiles

See how to profile, or customize, HL7® FHIR® resources for a specific use case by providing extensions and constraints. Profiled FHIR resources make up Implementation Guides that describe how to use HL7 FHIR in different ways, while also improving data consistency and manageability.    

Enjoy and check out more videos! 👍

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer