queryparser icon indicating copy to clipboard operation
queryparser copied to clipboard

Question - how to run queryparser

Open barshauli19 opened this issue 3 years ago • 2 comments

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.

barshauli19 avatar Apr 06 '21 14:04 barshauli19

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.

h4v0kh3l1 avatar Aug 24 '21 20:08 h4v0kh3l1

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 ] ) ]

l1x avatar Dec 25 '21 22:12 l1x