Skip to content

Question - how to run queryparser #57

Open

Description

@barshauli19

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.

Activity

  1. h4v0kh3l1 commented on Aug 24, 2021

    @h4v0kh3l1
    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.

  2. l1x commented on Dec 25, 2021

    @l1x

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions