How to use fn_threaded_conn method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

osmosis.py

Source:osmosis.py Github

copy

Full Screen

...297 # TODO: we can decide to reinit the Adapter here298 return False299 logger().info("Heartbeat received for %s", self.project_name)300 return True301 def fn_threaded_conn(self, fn: Callable[..., T], *args, **kwargs) -> Callable[..., T]:302 """Used for jobs which are intended to be submitted to a thread pool,303 the 'master' thread should always have an available connection for the duration of304 typical program runtime by virtue of the `_verify_connection` method.305 Threads however require singleton seeding"""306 def _with_conn() -> T:307 self.adapter.connections.set_connection_name()308 return fn(*args, **kwargs)309 return _with_conn310 @property311 def project_name(self) -> str:312 """dbt project name"""313 return self.config.project_name314 @property315 def project_root(self) -> str:...

Full Screen

Full Screen

server_v2.py

Source:server_v2.py Github

copy

Full Screen

...92 )93 try:94 loop = asyncio.get_running_loop()95 result = await loop.run_in_executor(96 None, project.fn_threaded_conn(project.execute_sql, query_with_limit)97 )98 except Exception as execution_err:99 return OsmosisErrorContainer(100 error=OsmosisError(101 code=OsmosisErrorCode.ExecuteSqlFailure,102 message=str(execution_err),103 data=execution_err.__dict__,104 )105 )106 # Re-extract compiled query and return data structure107 compiled_query = re.search(108 r"select \* from \(([\w\W]+)\) as osmosis_query", result.compiled_sql109 ).groups()[0]110 return OsmosisRunResult(111 rows=[list(row) for row in result.table.rows],112 column_names=result.table.column_names,113 compiled_sql=compiled_query.strip()[1:-1],114 raw_sql=query,115 )116@app.post(117 "/compile",118 response_model=Union[OsmosisCompileResult, OsmosisErrorContainer],119 responses={120 status.HTTP_404_NOT_FOUND: {"model": OsmosisErrorContainer},121 status.HTTP_500_INTERNAL_SERVER_ERROR: {"model": OsmosisErrorContainer},122 },123 openapi_extra={124 "requestBody": {125 "content": {"text/plain": {"schema": {"type": "string"}}},126 "required": True,127 },128 },129)130async def compile_sql(131 request: Request,132 response: Response,133 x_dbt_project: str = Header(default=DEFAULT),134) -> Union[OsmosisCompileResult, OsmosisErrorContainer]:135 """Compile dbt SQL against a registered project as determined by X-dbt-Project header"""136 dbt: DbtProjectContainer = app.state.dbt_project_container137 if x_dbt_project == DEFAULT:138 project = dbt.get_default_project()139 else:140 project = dbt.get_project(x_dbt_project)141 if project is None:142 response.status_code = status.HTTP_404_NOT_FOUND143 return OsmosisErrorContainer(144 error=OsmosisError(145 code=OsmosisErrorCode.ProjectNotRegistered,146 message="Project is not registered. Make a POST request to the /register endpoint first to register a runner",147 data={"registered_projects": dbt.registered_projects()},148 )149 )150 # Query Compilation151 query: str = (await request.body()).decode("utf-8").strip()152 if has_jinja(query):153 try:154 loop = asyncio.get_running_loop()155 compiled_query = (156 await loop.run_in_executor(157 None, project.fn_threaded_conn(project.compile_sql, query)158 )159 ).compiled_sql160 except Exception as compile_err:161 response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR162 return OsmosisErrorContainer(163 error=OsmosisError(164 code=OsmosisErrorCode.CompileSqlFailure,165 message=str(compile_err),166 data=compile_err.__dict__,167 )168 )169 else:170 compiled_query = query171 return OsmosisCompileResult(result=compiled_query)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful