<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to store SQL query output columns as variables to be used as parameters for API data call in in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110810#M43696</link>
    <description>&lt;PRE&gt;Adding&amp;nbsp;more&amp;nbsp;information&amp;nbsp;that&amp;nbsp;needs&amp;nbsp;to&amp;nbsp;be&amp;nbsp;done&amp;nbsp;in&amp;nbsp;below&amp;nbsp;: &lt;/PRE&gt;&lt;P&gt;My API Call looks something like this: ( Ignore the format &amp;amp; coding as this is a test code the actual code i have works fine)&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;from&lt;/SPAN&gt; zeep &lt;SPAN class=""&gt;import&lt;/SPAN&gt; Client
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; zeep.transports &lt;SPAN class=""&gt;import&lt;/SPAN&gt; Transport
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; requests &lt;SPAN class=""&gt;import&lt;/SPAN&gt; Session
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; requests.auth &lt;SPAN class=""&gt;import&lt;/SPAN&gt; HTTPBasicAuth
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; pyspark.sql.types &lt;SPAN class=""&gt;import&lt;/SPAN&gt; StructType, StructField, StringType, BooleanType
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; pyspark.sql.functions &lt;SPAN class=""&gt;import&lt;/SPAN&gt; lit
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class=""&gt;import&lt;/SPAN&gt; datetime

wsdl_url =  &lt;SPAN class=""&gt;"Test.xml"&lt;/SPAN&gt;

session = Session()
session.auth = HTTPBasicAuth(&lt;SPAN class=""&gt;'abc'&lt;/SPAN&gt;,&lt;SPAN class=""&gt;'password'&lt;/SPAN&gt;)

transport = Transport(session=session)

client = Client(wsdl=wsdl_url, transport=transport)

&lt;SPAN class=""&gt;# List all available services and ports&lt;/SPAN&gt;
&lt;SPAN class=""&gt;print&lt;/SPAN&gt;(client.wsdl.services)

&lt;SPAN class=""&gt;# Ensure the service and port names are correct&lt;/SPAN&gt;
service_name = &lt;SPAN class=""&gt;'Test'&lt;/SPAN&gt;
port_name = &lt;SPAN class=""&gt;'TestPort'&lt;/SPAN&gt;

&lt;SPAN class=""&gt;# Verify the available services and ports&lt;/SPAN&gt;
&lt;SPAN class=""&gt;for&lt;/SPAN&gt; service &lt;SPAN class=""&gt;in&lt;/SPAN&gt; client.wsdl.services.values():
    &lt;SPAN class=""&gt;print&lt;/SPAN&gt;(&lt;SPAN class=""&gt;f"Service: &lt;SPAN class=""&gt;{service.name}&lt;/SPAN&gt;"&lt;/SPAN&gt;)
    &lt;SPAN class=""&gt;for&lt;/SPAN&gt; port &lt;SPAN class=""&gt;in&lt;/SPAN&gt; service.ports.values():
        &lt;SPAN class=""&gt;print&lt;/SPAN&gt;(&lt;SPAN class=""&gt;f"  Port: &lt;SPAN class=""&gt;{port.name}&lt;/SPAN&gt;"&lt;/SPAN&gt;)

&lt;SPAN class=""&gt;# Bind to the correct service and port&lt;/SPAN&gt;
service = client.bind(&lt;SPAN class=""&gt;"Test"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"BasicHttpBinding_TestService"&lt;/SPAN&gt;)

request_data = {
    &lt;SPAN class=""&gt;'userAuth'&lt;/SPAN&gt;: {
        &lt;SPAN class=""&gt;'Nickname'&lt;/SPAN&gt;:&lt;SPAN class=""&gt;"Test"&lt;/SPAN&gt;
    },
    &lt;SPAN class=""&gt;'requestReference'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'test'&lt;/SPAN&gt;,
    &lt;SPAN class=""&gt;'request'&lt;/SPAN&gt;: {
        &lt;SPAN class=""&gt;'Subject'&lt;/SPAN&gt;: {
            &lt;SPAN class=""&gt;'Forename'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'Patricia'&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'Surname'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'Carroll'&lt;/SPAN&gt;
        },
        &lt;SPAN class=""&gt;'Address'&lt;/SPAN&gt;: {
            &lt;SPAN class=""&gt;'AddressLine1'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'123 Test Street'&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'AddressLine2'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;''&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'AddressLine3'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'LONDON'&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'Postcode'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'ABC 123'&lt;/SPAN&gt;
        },
        &lt;SPAN class=""&gt;'ConsentFlag'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;True&lt;/SPAN&gt;
    }
}

&lt;SPAN class=""&gt;if&lt;/SPAN&gt; service:
    response = service.PerformIDCheckV2(**request_data)
    
    &lt;SPAN class=""&gt;# Define the schema explicitly&lt;/SPAN&gt;
    schema = StructType([
        StructField(&lt;SPAN class=""&gt;"FirstName"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;),
        StructField(&lt;SPAN class=""&gt;"SurName"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;),
        StructField(&lt;SPAN class=""&gt;"response"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;),
        StructField(&lt;SPAN class=""&gt;"ETLApplyDateTime"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)
    ])&lt;/PRE&gt;&lt;P&gt;We can see above where i have hardcoded Patricia Name, i want those names to be passed as input from the above sql output&lt;/P&gt;</description>
    <pubDate>Fri, 21 Feb 2025 03:54:12 GMT</pubDate>
    <dc:creator>LearnDB1234</dc:creator>
    <dc:date>2025-02-21T03:54:12Z</dc:date>
    <item>
      <title>How to store SQL query output columns as variables to be used as parameters for API data call in DAT</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110792#M43689</link>
      <description>&lt;P&gt;I have a sql query which provides me with the below output :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Select&lt;/SPAN&gt; FirstName,LastName,Title &lt;SPAN class=""&gt;From&lt;/SPAN&gt; &lt;SPAN class=""&gt;Default&lt;/SPAN&gt;.Name

Tony         Gonzalez Mr
Tom          Brady    Mr
Patricia     Carroll  Miss&lt;/PRE&gt;&lt;P&gt;I would like to store FirstName, LastName &amp;amp; title column output rows as variable so i can use these variables as an input to my API data call which would take the names and return me with the data&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 19:53:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110792#M43689</guid>
      <dc:creator>LearnDB1234</dc:creator>
      <dc:date>2025-02-20T19:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to store SQL query output columns as variables to be used as parameters for API data call in</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110809#M43695</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/136231"&gt;@LearnDB1234&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;How are you doing today? Try storing the SQL query result into variables and then using them as input for your API call.&amp;nbsp;This approach ensures that you dynamically fetch data from SQL and use it as input for your API calls efficiently.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps! give a try and let me know.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Brahma&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 03:49:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110809#M43695</guid>
      <dc:creator>Brahmareddy</dc:creator>
      <dc:date>2025-02-21T03:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to store SQL query output columns as variables to be used as parameters for API data call in</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110810#M43696</link>
      <description>&lt;PRE&gt;Adding&amp;nbsp;more&amp;nbsp;information&amp;nbsp;that&amp;nbsp;needs&amp;nbsp;to&amp;nbsp;be&amp;nbsp;done&amp;nbsp;in&amp;nbsp;below&amp;nbsp;: &lt;/PRE&gt;&lt;P&gt;My API Call looks something like this: ( Ignore the format &amp;amp; coding as this is a test code the actual code i have works fine)&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;from&lt;/SPAN&gt; zeep &lt;SPAN class=""&gt;import&lt;/SPAN&gt; Client
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; zeep.transports &lt;SPAN class=""&gt;import&lt;/SPAN&gt; Transport
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; requests &lt;SPAN class=""&gt;import&lt;/SPAN&gt; Session
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; requests.auth &lt;SPAN class=""&gt;import&lt;/SPAN&gt; HTTPBasicAuth
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; pyspark.sql.types &lt;SPAN class=""&gt;import&lt;/SPAN&gt; StructType, StructField, StringType, BooleanType
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; pyspark.sql.functions &lt;SPAN class=""&gt;import&lt;/SPAN&gt; lit
&lt;SPAN class=""&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class=""&gt;import&lt;/SPAN&gt; datetime

wsdl_url =  &lt;SPAN class=""&gt;"Test.xml"&lt;/SPAN&gt;

session = Session()
session.auth = HTTPBasicAuth(&lt;SPAN class=""&gt;'abc'&lt;/SPAN&gt;,&lt;SPAN class=""&gt;'password'&lt;/SPAN&gt;)

transport = Transport(session=session)

client = Client(wsdl=wsdl_url, transport=transport)

&lt;SPAN class=""&gt;# List all available services and ports&lt;/SPAN&gt;
&lt;SPAN class=""&gt;print&lt;/SPAN&gt;(client.wsdl.services)

&lt;SPAN class=""&gt;# Ensure the service and port names are correct&lt;/SPAN&gt;
service_name = &lt;SPAN class=""&gt;'Test'&lt;/SPAN&gt;
port_name = &lt;SPAN class=""&gt;'TestPort'&lt;/SPAN&gt;

&lt;SPAN class=""&gt;# Verify the available services and ports&lt;/SPAN&gt;
&lt;SPAN class=""&gt;for&lt;/SPAN&gt; service &lt;SPAN class=""&gt;in&lt;/SPAN&gt; client.wsdl.services.values():
    &lt;SPAN class=""&gt;print&lt;/SPAN&gt;(&lt;SPAN class=""&gt;f"Service: &lt;SPAN class=""&gt;{service.name}&lt;/SPAN&gt;"&lt;/SPAN&gt;)
    &lt;SPAN class=""&gt;for&lt;/SPAN&gt; port &lt;SPAN class=""&gt;in&lt;/SPAN&gt; service.ports.values():
        &lt;SPAN class=""&gt;print&lt;/SPAN&gt;(&lt;SPAN class=""&gt;f"  Port: &lt;SPAN class=""&gt;{port.name}&lt;/SPAN&gt;"&lt;/SPAN&gt;)

&lt;SPAN class=""&gt;# Bind to the correct service and port&lt;/SPAN&gt;
service = client.bind(&lt;SPAN class=""&gt;"Test"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"BasicHttpBinding_TestService"&lt;/SPAN&gt;)

request_data = {
    &lt;SPAN class=""&gt;'userAuth'&lt;/SPAN&gt;: {
        &lt;SPAN class=""&gt;'Nickname'&lt;/SPAN&gt;:&lt;SPAN class=""&gt;"Test"&lt;/SPAN&gt;
    },
    &lt;SPAN class=""&gt;'requestReference'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'test'&lt;/SPAN&gt;,
    &lt;SPAN class=""&gt;'request'&lt;/SPAN&gt;: {
        &lt;SPAN class=""&gt;'Subject'&lt;/SPAN&gt;: {
            &lt;SPAN class=""&gt;'Forename'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'Patricia'&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'Surname'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'Carroll'&lt;/SPAN&gt;
        },
        &lt;SPAN class=""&gt;'Address'&lt;/SPAN&gt;: {
            &lt;SPAN class=""&gt;'AddressLine1'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'123 Test Street'&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'AddressLine2'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;''&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'AddressLine3'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'LONDON'&lt;/SPAN&gt;,
            &lt;SPAN class=""&gt;'Postcode'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'ABC 123'&lt;/SPAN&gt;
        },
        &lt;SPAN class=""&gt;'ConsentFlag'&lt;/SPAN&gt;: &lt;SPAN class=""&gt;True&lt;/SPAN&gt;
    }
}

&lt;SPAN class=""&gt;if&lt;/SPAN&gt; service:
    response = service.PerformIDCheckV2(**request_data)
    
    &lt;SPAN class=""&gt;# Define the schema explicitly&lt;/SPAN&gt;
    schema = StructType([
        StructField(&lt;SPAN class=""&gt;"FirstName"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;),
        StructField(&lt;SPAN class=""&gt;"SurName"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;),
        StructField(&lt;SPAN class=""&gt;"response"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;),
        StructField(&lt;SPAN class=""&gt;"ETLApplyDateTime"&lt;/SPAN&gt;, StringType(), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)
    ])&lt;/PRE&gt;&lt;P&gt;We can see above where i have hardcoded Patricia Name, i want those names to be passed as input from the above sql output&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 03:54:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110810#M43696</guid>
      <dc:creator>LearnDB1234</dc:creator>
      <dc:date>2025-02-21T03:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to store SQL query output columns as variables to be used as parameters for API data call in</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110812#M43698</link>
      <description>&lt;P&gt;Hi Brahma,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response, i am new to this so if you can please provide me with the pseudo code that helps.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 03:56:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110812#M43698</guid>
      <dc:creator>LearnDB1234</dc:creator>
      <dc:date>2025-02-21T03:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to store SQL query output columns as variables to be used as parameters for API data call in</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110813#M43699</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/136231"&gt;@LearnDB1234&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Here is the approach - You can make your API call dynamic by first running your SQL query and storing the results in a DataFrame. Then, you can loop through each row in the DataFrame and extract the FirstName&amp;nbsp;and LastName values, passing them into your API request instead of hardcoding them.&lt;/P&gt;&lt;P&gt;Here’s a simple way to do it -&lt;/P&gt;&lt;P&gt;1. Run your SQL query to get FirstName, LastName, and Title into a DataFrame.&lt;/P&gt;&lt;P&gt;2. Convert the DataFrame into a list so you can iterate through each row.&lt;/P&gt;&lt;P&gt;3. Inside a loop, dynamically insert FirstName and LastName into your API request.&lt;/P&gt;&lt;P&gt;4. Call the API for each person and collect responses.&lt;/P&gt;&lt;P&gt;5. Store responses in a new DataFrame for further processing.&lt;/P&gt;&lt;P&gt;This way, every API request will use actual names from your SQL output, removing the need for hardcoded values. It keeps things clean, scalable, and automated.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Brahma&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 04:02:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-store-sql-query-output-columns-as-variables-to-be-used-as/m-p/110813#M43699</guid>
      <dc:creator>Brahmareddy</dc:creator>
      <dc:date>2025-02-21T04:02:21Z</dc:date>
    </item>
  </channel>
</rss>

