def test_scope(): _remove_all_new_packages(pkgmanager) package = os.path.join(path_to_packages, "testpackageA-0.0.1.zip") def get_location(): import testpackageA return testpackageA.__file__ _revotesterconnection = sqlmlutils.ConnectionInfo(server="localhost", database="AirlineTestDB", uid="Tester", pwd="FakeT3sterPwd!") revopkgmanager = SQLPackageManager(_revotesterconnection) revoexecutor = SQLPythonExecutor(_revotesterconnection) revopkgmanager.install(package, scope=Scope.private_scope()) private_location = revoexecutor.execute_function_in_sql(get_location) pkg_name = "testpackageA" pyexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=False) revopkgmanager.uninstall(pkg_name, scope=Scope.private_scope()) revopkgmanager.install(package, scope=Scope.public_scope()) public_location = revoexecutor.execute_function_in_sql(get_location) assert private_location != public_location pyexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=True, class_to_check='ClassA') revopkgmanager.uninstall(pkg_name, scope=Scope.public_scope()) revoexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=False) pyexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=False)
# Internal ODBC connection string used by process executing inside SQL Server connection_string = "Driver=SQL Server;Server=localhost;Database=AirlineTestDB;Trusted_Connection=Yes;" engine = sqlalchemy.create_engine("mssql+pyodbc:///?odbc_connect={}".format(parse.quote_plus(connection_string))) input_df = pd.read_sql("select top 200 ArrDelay,CRSDepTime,DayOfWeek from {}".format(input_table), engine).dropna() pca = PCA(n_components=2) components = pca.fit_transform(input_df) output_df = pd.DataFrame(components) output_df.to_sql(output_table, engine, if_exists="replace") connection = sqlmlutils.ConnectionInfo(server="localhost", database="AirlineTestDB") input_table = "airline5000" output_table = "AirlineDemoPrincipalComponents" sp_name = "SavePrincipalComponents" sqlpy = sqlmlutils.SQLPythonExecutor(connection) if sqlpy.check_sproc(sp_name): sqlpy.drop_sproc(sp_name) sqlpy.create_sproc_from_function(sp_name, principal_components) # You can check the stored procedure exists in the db with this: assert sqlpy.check_sproc(sp_name)
# Copyright(c) Microsoft Corporation. # Licensed under the MIT license. import sqlmlutils def foo(): return "bar" sqlpython = sqlmlutils.SQLPythonExecutor( sqlmlutils.ConnectionInfo(server="localhost", database="master")) result = sqlpython.execute_function_in_sql(foo) assert result == "bar"
import sqlmlutils connection=sqlmlutils.ConnectionInfo(server="localhost",database="Test") sqlmlutils.SQLPackageManager(connection).install("textblob")
# Copyright(c) Microsoft Corporation. All rights reserved. # Licensed under the MIT license. import sqlmlutils def foo(): return "bar" sqlpython = sqlmlutils.SQLPythonExecutor(sqlmlutils.ConnectionInfo(server="localhost", database="master")) result = sqlpython.execute_function_in_sql(foo) assert result == "bar"