Skip to content

Commit

Permalink
Fixes to resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
greenmtnboy committed Mar 30, 2024
1 parent 262029c commit 20ce003
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 16 deletions.
42 changes: 37 additions & 5 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

STATEMENT_LIMIT = 100

PARSE_DEPENDENCY_RESOLUTION_ATTEMPTS = 50

app = FastAPI()


Expand Down Expand Up @@ -183,11 +185,41 @@ def safe_format_query(input: str) -> str:

def parse_env_from_full_model(input: ModelInSchema) -> Environment:
env = Environment()
for source in input.sources:
if source.alias:
env.parse(source.contents, namespace=source.alias)
else:
env.parse(source.contents)

parsed = dict()
successful = set()
attempts = 0
exception = None
# attempt to determine the dependency order of inputs
# TODO: do some smarter first path dependency resolution based on imports
while (
len(parsed) < len(input.sources)
and attempts < PARSE_DEPENDENCY_RESOLUTION_ATTEMPTS
):
attempts += 1
for source in input.sources:
if source.alias in successful:
continue
try:
if source.alias:
new = Environment(namespace=source.alias)
for k, v in parsed.items():
new.add_import(k, v)
new.parse(source.contents)
env.add_import(source.alias, new)
parsed[source.alias] = new
else:
env.parse(source.contents)
successful.add(source.alias)
except Exception as e:
exception = e
pass
success = len(successful) == len(input.sources)
if not success:
raise ValueError(
f"unable to parse input models after {attempts} attempts; successfully parsed {parsed}; error was {str(exception)}, have {[c.address for c in env.concepts.values()]}"
)

return env


Expand Down
34 changes: 32 additions & 2 deletions backend/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi.testclient import TestClient
from ..main import ConnectionInSchema
from ..main import ConnectionInSchema, parse_env_from_full_model, ModelInSchema, ModelSourceInSchema
from typing import List, Mapping
from trilogy_public_models import models as public_models

Expand Down Expand Up @@ -76,7 +76,37 @@ def test_read_models(test_client: TestClient):
# else:
# raise ValueError(response)
# sleep(1)
# if attempts > max_attempts:
# if attempts > max_at,tempts:
# raise ValueError(f"Too many attempts, last response {response}")
# # basic check that they ran async and not 5+5 seconds
# assert (datetime.now() - datetime1).seconds < 7


def test_parse_full():
input = ModelInSchema(name='test', sources=[
ModelSourceInSchema(alias='', contents='select test.constant;'),
ModelSourceInSchema(alias='test', contents='const constant <-1;')

])
parsed = parse_env_from_full_model(input)

test = {
"name": "bigquery.google_analytics",
"sources": [
{
"alias": "fundiverse",
"contents": "\nkey user_pseudo_id int;\n\ndatasource fundiverse(\n event_date: generic.event_date,\n user_pseudo_id: user_pseudo_id,\n event_time: generic.event_time,\n)\ngrain (generic.event_time)\naddress `preqldata.analytics_411641820.events_*`\n;"
},
{
"alias": "pypreql",
"contents": "\nkey user_pseudo_id int;\n\ndatasource pypreql(\n event_date: generic.event_date,\n user_pseudo_id: user_pseudo_id,\n event_time: generic.event_time,\n)\ngrain (generic.event_time)\naddress `preqldata.analytics_417320071.events_*`\n;"
},
{
"alias": "generic",
"contents": "\n\nkey event_time int;\nkey event_date string;\n\n"
}
]
}
input = ModelInSchema.model_validate(test)

parsed = parse_env_from_full_model(input)
14 changes: 8 additions & 6 deletions frontend/src/components/editor/EditEditorPopup.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@


<template>
<v-dialog v-model="dialog" max-width="500">
<v-dialog class="override-style" v-model="dialog" max-width="500" min-width=400>
<template v-slot:activator="{ props }">
<v-btn class="sidebar-detail-btn square-corner" v-bind="props" :density="density" icon="mdi-edit"
<v-btn class="sidebar-detail-btn square-corner" v-bind="props" :density="density"
icon="mdi-edit"
>
Edit
</v-btn>
Expand Down Expand Up @@ -35,12 +36,16 @@
</v-dialog>
</template>
<style scoped>
.override-style {
display: 'auto';
width: '100%';
}
</style>
<script lang="ts">
import { mapActions, mapGetters } from 'vuex';
export default {
name: "AddEditorTab",
name: "EditEditorPopup",
data() {
return {
Expand Down Expand Up @@ -72,9 +77,6 @@ export default {
return this.connections.filter((c) => c.name != this.unconnectedLabel)
}
},
mounted: () => {
// console.log(this.connections)
},
methods: {
...mapActions(['editEditor', 'setActiveEditor']),
showPopup() {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/editor/QueryResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
display: flex;
flex-direction: column;
flex: 1 1 100%;
height: 100%;
height: 95%;
}
.query-result {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
flex: 1 1 100%;
height: 100%;
height: 95%;
}
.result-table {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default {
syntax: 'preql',
}).then(() => {
local.editor = local.name
return localAddEditortoModel()
return local.addEditorToModel()
})
}
Expand Down

0 comments on commit 20ce003

Please sign in to comment.