Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - how to run queryparser #57

Open
barshauli19 opened this issue Apr 6, 2021 · 2 comments
Open

Question - how to run queryparser #57

barshauli19 opened this issue Apr 6, 2021 · 2 comments

Comments

@barshauli19
Copy link

Hi,
How can I run queryparser not with stack ghci ?
In which way can I run it with cmd ? Receiving query file as input and file name to output ?
How can we make it more generic that it is not using stack ghci.
Can you kindly please provide us some examples ?

Sorry I'm not families with stack or Haskall at all.

@h4v0kh3l1
Copy link
Contributor

I believe if you want to develop queryparser, you will need to use stack. However, if you want to just use queryparser in a Haskell environment, there are packages on Hackage that you can directly import.
If you're looking for a downloadable binary executable, we don't have one published. However, try following along with the readme to get the demo up and running.

@l1x
Copy link

l1x commented Dec 25, 2021

Hi, How can I run queryparser not with stack ghci ? In which way can I run it with cmd ? Receiving query file as input and file name to output ? How can we make it more generic that it is not using stack ghci. Can you kindly please provide us some examples ?

Sorry I'm not families with stack or Haskall at all.

This starts up the shell:

stack ghci

This sets the shell prompt right:

:set prompt "sql> "

This is how you can parse a simple statement of PrestoSQL:

sql> Database.Sql.Presto.Parser.parse  "SELECT 1;"
Right (PrestoStandardSqlStatement (QueryStmt (QuerySelect (Range {start = Position {positionLine = 1, positionColumn = 0, positionOffset = 0}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}) (Select {selectInfo = Range {start = Position {positionLine = 1, positionColumn = 0, positionOffset = 0}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}, selectCols = SelectColumns {selectColumnsInfo = Range {start = Position {positionLine = 1, positionColumn = 7, positionOffset = 7}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}, selectColumnsList = [SelectExpr (Range {start = Position {positionLine = 1, positionColumn = 7, positionOffset = 7}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}) [ColumnAlias (Range {start = Position {positionLine = 1, positionColumn = 7, positionOffset = 7}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}) "_col0" (ColumnAliasId 1)] (ConstantExpr (Range {start = Position {positionLine = 1, positionColumn = 7, positionOffset = 7}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}) (NumericConstant (Range {start = Position {positionLine = 1, positionColumn = 7, positionOffset = 7}, end = Position {positionLine = 1, positionColumn = 8, positionOffset = 8}}) "1"))]}, selectFrom = Nothing, selectWhere = Nothing, selectTimeseries = Nothing, selectGroup = Nothing, selectHaving = Nothing, selectNamedWindow = Nothing, selectDistinct = Distinct False}))))

This is how you can use the Demo setup:

sql> import Demo
sql> demoAllAnalyses "SELECT * FROM foo"
Tables accessed:
    public.foo
Columns accessed by clause:
    public.foo.a        SELECT
    public.foo.b        SELECT
    public.foo.c        SELECT
Joins:
    no joins
Table lineage:
    no tables modified

This depends on the content of the demo folder. There is for example a catalog setup that has some tables:

-- and construct a catalog, with tables `foo` (columns a, b, and c) and `bar` (columns x, y, and z)
catalog :: Catalog
catalog = makeDefaultingCatalog catalogMap [defaultSchema] defaultDatabase
  where
    defaultDatabase :: DatabaseName ()
    defaultDatabase = DatabaseName () "defaultDatabase"

    defaultSchema :: UQSchemaName ()
    defaultSchema = mkNormalSchema "public" ()

    foo :: (UQTableName (), SchemaMember)
    foo = ( QTableName () None "foo", persistentTable [ QColumnName () None "a"
                                                      , QColumnName () None "b"
                                                      , QColumnName () None "c"
                                                      ] )

    bar :: (UQTableName (), SchemaMember)
    bar = ( QTableName () None "bar", persistentTable [ QColumnName () None "x"
                                                      , QColumnName () None "y"
                                                      , QColumnName () None "z"
                                                      ] )

    catalogMap :: CatalogMap
    catalogMap = HMS.singleton defaultDatabase $
                     HMS.fromList [ ( defaultSchema, HMS.fromList [ foo , bar ] ) ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants