Streamline Syntax Migration: Unleashing Snowflake Artic’s Power
Syntax migration is often a challenging aspect of data migration projects. Adapting SQL queries from one syntax to another can be a painstaking process. In this article, we’ll explore how you can harness the power of Snowflake’s Enterprise-grade Language Model (LLM) Artic to simplify syntax migration.
Before diving in, it’s important to ensure you have Artic set up in your Snowflake instance. If you haven’t done so already, refer to my previous post where I walk through the setup process: [How to Set Up Snowflake’s Enterprise LLM Artic in Snowflake ](https://medium.com/@mebinjoy/how-to-set-up-snowflakes-enterprise-llm-artic-in-snowflake-without-snowflake-cortex-06362e6c22bb).
Once Artic is configured, the next step is to create a Streamlit app within Snowflake. Ensure that you create the Streamlit app in the same schema and database where Artic is configured. Streamlit is a powerful tool for rapidly developing data applications. For more information, refer to the Snowflake documentation on Streamlit: [About Streamlit](https://docs.snowflake.com/en/developer-guide/streamlit/about-streamlit).
In the Streamlit editor, simply copy and paste the provided code snippet:
# Import python packages
import streamlit as st
from snowflake.snowpark.context import get_active_session
import streamlit as st
from snowflake.snowpark.functions import *
session = get_active_session()
st.title("Snowflake Artic - Query Converter")
sql_options = ['MySQL','SQL Server','Oracle',
'Databricks','Spark','Druid',]
source_lang = st.selectbox(label="Query Type",options=sql_options)
source_query = st.text_area(label="Enter your query :")
conversion_prompt = f"""
You are an SQL conversion expert. Convert the given query to Snowflake syntax.
Give the query in Snowflake Syntax. Highlight the changes from source. Also suggest optimizations if needed.
The query is {source_query} , which is in {source_lang} syntax.
"""
snow_df = session.create_dataframe([[conversion_prompt]],schema=['prompt'])
generate = st.button(label="Generate Snowflake Query")
if generate:
res_df = snow_df.select(call_udf("artic", col("prompt")).alias('res')).to_pandas()
st.markdown(res_df['RES'][0])
This code allows users to input the source query and select the source syntax type. After clicking the “Generate Query” button, Snowflake’s Artic function is invoked through Snowpark functions to convert the query into Snowflake syntax. The converted query is then displayed, along with any suggested optimizations.
Feel free to customize and refine the prompt provided for better results.
Once you’ve copied and run the code, you’ll have your very own syntax converter powered by Snowflake Artic.
Stay tuned for more in-depth coverage of Snowflake Artic in future articles. Happy querying!