Skip to content

Commit

Permalink
Added the --wait-on-stdin (-W) option to resolve issue #1.
Browse files Browse the repository at this point in the history
Removed the now unnecessary base-compat constraint given
regex-1.0.*-r1.  Removed extra 'import Crypto.Hash' line in
UtilsUnsafe.hs.  Corrected some small documentation issues.  Updated
the scidb-hquery.cabal and stack.yaml files.  These changes did not
change the primitive API of hquery.  Tested lightly with SciDB 19.11
community edition.
  • Loading branch information
mdgabriel committed Mar 22, 2020
1 parent 3cfc593 commit b568c3e
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
## 2.8.0.436 -- 2019-11-13

* Added a base-compat constraint so that regex always compiles and added tested-with to the cabal file. Changed the stack resolver to lts-14.14. Small improvement in the documentation.

## 2.8.0.437 -- 2020-03-23

* Added the --wait-on-stdin (-W) option to resolve issue #1. Removed the now unnecessary base-compat constraint given regex-1.0.*-r1. Removed extra 'import Crypto.Hash' line in UtilsUnsafe.hs. Corrected some small documentation issues. Updated the scidb-hquery.cabal and stack.yaml files. These changes did not change the primitive API of hquery. Tested lightly with SciDB 19.11 community edition.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NAME
hquery - Haskell query for SciDB via shim
SYNOPSIS
hquery [-V n] [-t hstfile] [-c certstore] [-n]
hquery [-V n] [-W] [-t hstfile] [-c certstore] [-n]
[-r http[s]] [-i host] [-p port] [-a true|false]
[-e true|false] [-o fmt] [-b num] [-d|-s]
[-u usr] [-w pw]
Expand Down Expand Up @@ -243,18 +243,22 @@ OPTIONS
-V1 Shows some HTTP exceptions and trace information (--verbose=1).
-V2 Shows additional URL information (--verbose=2).
-W Wait on stdin (--wait-on-stdin). In some cases, hquery can
determine that stdin is ready in which case it is consumed.
The -W option guarantees that hquery waits on stdin.
OPERANDS
SciDB AFL queries.
USAGE NOTES
The development of the utility hquery began with SciDB community
edition 13 and continued with 14, 15, 16, 18, and 19.
This version of hquery has been lightly tested with ghc
version 8.2.2 and 8.6.5 and SciDB 18.1 and 19.3 community edition.
This version of hquery has been lightly tested with ghc version
8.2.2 and 8.6.5 and SciDB 18.1, 19.3 and 19.11 community edition.
Currently the command hquery has never been tested on a SciDB
enterprise edition, and thus it is not known if SciDB
authorization (-s) or prefix (-x) actually works.
enterprise edition, and thus it is not known if SciDB authorization
(-s) or a prefix (-x) actually works.
EXAMPLES
To list all currently defined arrays with SciDB authorization
Expand Down Expand Up @@ -297,6 +301,11 @@ EXAMPLES
hquery -i coordinator -b 0 -x "set_namespace('sensor_data');" \
"list('arrays');"
To find and project the arrays A, B, C and D to be removed, use
hquery -otsv "project(apply(filter(list('arrays'),regex(name,'A|B|C|D')),
remove,'remove('+name+');'),remove);" | hquery -W
To display a synopsis of this internal manual page, use
hquery -y
Expand Down
24 changes: 10 additions & 14 deletions scidb-hquery.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cabal-version: 2.4
name: scidb-hquery
version: 2.8.0.436
version: 2.8.0.437
license: GPL-3.0-only
license-file: LICENSE
copyright: All rights reserved 2014-19(c).
maintainer: marcus@gabriel.name
author: Marcus D. Gabriel
tested-with: ghc ==8.6.5
homepage: https://github.com/mdgabriel/scidb-hquery.git
bug-reports: https://github.com/mdgabriel/scidb-hquery/issues
synopsis: Haskell query for SciDB via shim
Expand All @@ -14,19 +15,18 @@ description:
interacitve session with a SciDB server using SciDB's shim
protocol at host localhost and port 8080. See the [homepage](https://github.com/mdgabriel/scidb-hquery.git),
"hquery -m", and [www.paradigm4.com](http://www.paradigm4.com) for more infomation.
Note that scidb-hquery builds with cabal v2-build and stack resolver lts-14.14.
Note that scidb-hquery builds with cabal v2-build and stack resolver lts-14.27.
category: program, client, database, library
build-type: Custom
extra-source-files:
CHANGELOG.md
README.md
src/SciDbAFL.cf
tested-with: GHC==8.6.5

source-repository head
type: git
location: https://github.com/mdgabriel/scidb-hquery.git
tag: 2.8.0.436
tag: 2.8.0.437

custom-setup
setup-depends: base >=4.12.0.0 && <4.13,
Expand Down Expand Up @@ -69,19 +69,17 @@ library
cryptonite >=0.25 && <0.27,
data-default-class >=0.1.2.0 && <0.2,
exceptions >=0.10.2 && <0.11,
haskeline >=0.7.5.0 && <0.8,
haskeline >=0.7.5.0 && <0.9,
hostname-validate >=1.0.0 && <1.1,
http-client >=0.5.14 && <0.7,
http-client-tls >=0.3.5.3 && <0.4,
http-conduit >=2.3.7.1 && <2.4,
http-types >=0.12.3 && <0.13,
memory >=0.14.18 && <0.15,
memory >=0.14.18 && <0.16,
mtl >=2.2.2 && <2.3,
network >=2.8.0.1 && <3.2,
process >=1.6.5.0 && <1.7,
-- base-compat constraint needed so that regex continues to compile
base-compat >=0.6 && <0.11,
regex >=1.0.2.0 && <1.1,
regex >=1.0.2.0 && <1.2,
safe >=0.3.17 && <0.4,
split >=0.2.3.3 && <0.3,
terminal-size >=0.3.2.1 && <0.4,
Expand Down Expand Up @@ -125,19 +123,17 @@ executable hquery
directory >=1.3.3.0 && <1.4,
exceptions >=0.10.2 && <0.11,
filepath >=1.4.2.1 && <1.5,
haskeline >=0.7.5.0 && <0.8,
haskeline >=0.7.5.0 && <0.9,
hostname-validate >=1.0.0 && <1.1,
http-client >=0.5.14 && <0.7,
http-client-tls >=0.3.5.3 && <0.4,
http-conduit >=2.3.7.1 && <2.4,
http-types >=0.12.3 && <0.13,
memory >=0.14.18 && <0.15,
memory >=0.14.18 && <0.16,
mtl >=2.2.2 && <2.3,
network >=2.8.0.1 && <3.2,
process >=1.6.5.0 && <1.7,
-- base-compat constraint needed so that regex continues to compile
base-compat >=0.6 && <0.11,
regex >=1.0.2.0 && <1.1,
regex >=1.0.2.0 && <1.2,
safe >=0.3.17 && <0.4,
split >=0.2.3.3 && <0.3,
terminal-size >=0.3.2.1 && <0.4,
Expand Down
2 changes: 2 additions & 0 deletions src/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ data Environment =
, password :: String -- ^ Password for username
, operands :: [String] -- ^ List of queries
, file :: String -- ^ File of queries
, waitOnStdIn :: Bool -- ^ Wait on stdin
, help :: Bool -- ^ @-h@, display help summary
, license :: Bool -- ^ @-l@, display license terms
, manual :: Bool -- ^ @-m@, display internal man page
Expand Down Expand Up @@ -86,6 +87,7 @@ defaultEnv =
, password = "" -- Password needed for -d or -s option
, operands = [] -- No operands by default, i.e., interactive mode
, file = "" -- No file of queries by default
, waitOnStdIn = False -- Wait on stdin
, help = False -- False or off by default
, license = False -- False or off by default
, manual = False -- False or off by default
Expand Down
8 changes: 4 additions & 4 deletions src/HQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import Environment (Environment(certStore,defFetch,de
,defReadingLines,defPrefix,digestAuth
,digestHeaders,file,history,host,insecure
,operands,password,port,protocol,sciDbVersion
,scidbAuth,username,verbose)
,scidbAuth,username,verbose,waitOnStdIn)
,defaultEnv,maybePort,Verbosity(..))
import ErrM (Err(..))
import Interpreter (Results(..),interpret)
Expand Down Expand Up @@ -201,7 +201,7 @@ maybeSetDigestAuth r =
-- 'defNumber' lines (23 by default); an exception occurs when
-- attempting to fetch no returned lines. If fetch is false, do not
-- fetch any lines. For exmample, fetch should be set to false for
-- store, create and load. See 'interpretOperatorId' in
-- store, create and load. See 'interpretFuncId' in
-- Interpreter.hs for details.

unsafeRunQuery :: Environment -> String -> IO String
Expand Down Expand Up @@ -240,11 +240,11 @@ hquery e = withSocketsDo (runReaderT (evalStateT _hquery defaultParam) e)
do initParam
e <- ask
r <- liftIO $ hReady stdin
if null (operands e) && null (file e) && not r
if null (operands e) && null (file e) && not (waitOnStdIn e) && not r
then do liftIO $ putStrLn ("SciDB version "++sciDbVersion e)
executeQuery DontExitOnBad "list('instances');"
iQuery
else do c <- liftIO $ if r then getContents else return ""
else do c <- liftIO $ if r || waitOnStdIn e then getContents else return ""
f <- liftIO $ (if null (file e) then return else readFile) (file e)
let a = intercalate "\n" ("":(nolines <$> operands e))
executeQuery ExitOnBad (c ++ f ++ a)
Expand Down
27 changes: 19 additions & 8 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ for 'hquery':
> hquery - Haskell query for SciDB via shim
>
> SYNOPSIS
> hquery [-V n] [-t hstfile] [-c certstore] [-n]
> hquery [-V n] [-W] [-t hstfile] [-c certstore] [-n]
> [-r http[s]] [-i host] [-p port] [-a true|false]
> [-e true|false] [-o fmt] [-b num] [-d|-s] [-u usr] [-w pw]
> [-f qyfile] [query...]
Expand Down Expand Up @@ -276,18 +276,22 @@ for 'hquery':
> -V1 Shows some HTTP exceptions and trace information (--verbose=1).
> -V2 Shows additional URL information (--verbose=2).
>
> -W Wait on stdin (--wait-on-stdin). In some cases, hquery can
> determine that stdin is ready in which case it is consumed.
> The -W option guarantees that hquery waits on stdin.
>
> OPERANDS
> SciDB AFL queries.
>
> USAGE NOTES
> The development of the utility hquery began with SciDB community
> edition 13 and continued with 14, 15, 16, 18, and 19.
>
> This version of hquery has been lightly tested with ghc
> version 8.2.2 and 8.6.5 and SciDB 18.1 and 19.3 community edition.
> This version of hquery has been lightly tested with ghc version
> 8.2.2 and 8.6.5 and SciDB 18.1, 19.3 and 19.11 community edition.
> Currently the command hquery has never been tested on a SciDB
> enterprise > edition, and thus it is not known if SciDB
> authorization (-s) or prefix (-x) actually works.
> enterprise edition, and thus it is not known if SciDB authorization
> (-s) or a prefix (-x) actually works.
>
> EXAMPLES
> To list all currently defined arrays with SciDB authorization required,
Expand Down Expand Up @@ -330,6 +334,11 @@ for 'hquery':
> hquery -i coordinator -b 0 -x "set_namespace('sensor_data');" \
> "list('arrays');"
>
> To find and project the arrays A, B, C and D to be removed, use
>
> hquery -otsv "project(apply(filter(list('arrays'),regex(name,'A|B|C|D')),
> remove,'remove('+name+');'),remove);" | hquery -W
>
> To display a synopsis of this internal manual page, use
>
> hquery -y
Expand Down Expand Up @@ -455,9 +464,9 @@ config =
Config {
argOrder = RequireOrder,
-- Update revision number: toggle case
release = "2.8.0.436",
release = "2.8.0.437",
flagsOps = " [[-g|-h|-l|-m|-v|-y] |"++
"\n [-V n] [-t hstfile] [-c certstore] [-n]"++
"\n [-V n] [-W] [-t hstfile] [-c certstore] [-n]"++
"\n [-r http[s]] [-i host] [-p port] [-a true|false]"++
"\n [-e true|false] [-o fmt] [-b num] [-d|-s] [-u usr] [-w pw]"++
"\n [-f qyfile] [query...]"++
Expand All @@ -475,7 +484,7 @@ Flags set as a function of the command line options supplied.
-}
data Flag = Help | License | Manual | Synopsis | Version | Verbose Verbosity
| Host String | Port String | Protocol String | File FilePath
| History String | Username String | Password String
| History String | Username String | Password String | WaitOnStdIn
| Fetch String | Format String | Number String | VersionSciDb
| DigestAuth | SciDbAuth | CertStore String | Insecure
| ReadingLines String | Prefix String
Expand Down Expand Up @@ -508,6 +517,7 @@ options =
, Option "y" ["synopsis"] (NoArg Synopsis) "Help synopsis."
, Option "x" ["prefix"] (ReqArg Prefix "PREFIX") "Prefix to execute before a query by shim."
, Option "V" ["verbose"] (OptArg inpver "012") "Verbose information to stderr."
, Option "W" ["wait-on-stdin"] (NoArg WaitOnStdIn) "Wait on stdin."
]
where inpver :: Maybe String -> Flag
inpver ms = Verbose $ case (fromMaybe (-1) . readMay . fromMaybe "1") ms of
Expand Down Expand Up @@ -546,6 +556,7 @@ updateEnvField env opt =
Version -> env{version = True}
VersionSciDb->env{versionSciDb= True}
Verbose v -> env{verbose = v}
WaitOnStdIn-> env{waitOnStdIn = True}
where tOrF s = case fmap toLower s of
"true" -> Just True
"false" -> Just False
Expand Down
21 changes: 15 additions & 6 deletions src/Manual.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internalManual =
" hquery - Haskell query for SciDB via shim\n"++
"\n"++
"SYNOPSIS\n"++
" hquery [-V n] [-t hstfile] [-c certstore] [-n]\n"++
" hquery [-V n] [-W] [-t hstfile] [-c certstore] [-n]\n"++
" [-r http[s]] [-i host] [-p port] [-a true|false]\n"++
" [-e true|false] [-o fmt] [-b num] [-d|-s] [-u usr] [-w pw]\n"++
" [-f qyfile] [query...]\n"++
Expand Down Expand Up @@ -227,18 +227,22 @@ internalManual =
" -V1 Shows some HTTP exceptions and trace information (--verbose=1).\n"++
" -V2 Shows additional URL information (--verbose=2).\n"++
"\n"++
" -W Wait on stdin (--wait-on-stdin). In some cases, hquery can\n"++
" determine that stdin is ready in which case it is consumed.\n"++
" The -W option guarantees that hquery waits on stdin.\n"++
"\n"++
"OPERANDS\n"++
" SciDB AFL queries.\n"++
"\n"++
"USAGE NOTES\n"++
" The development of the utility hquery began with SciDB community\n"++
" edition 13 and continued with 14, 15, 16, 18, and 19.\n"++
"\n"++
" This version of hquery has been lightly tested with ghc\n"++
" version 8.2.2 and 8.6.5 and SciDB 18.1 and 19.3 community edition.\n"++
" Currently the command hquery has never been tested on a SciDB\n"++
" enterprise edition, and thus it is not known if SciDB\n"++
" authorization (-s) or prefix (-x) actually works.\n"++
" This version of hquery has been lightly tested with ghc version\n"++
" 8.2.2 and 8.6.5 and SciDB 18.1, 19.3 and 19.11 community edition.\n"++
" Currently the command hquery has never been tested on a SciDB\n"++
" enterprise edition, and thus it is not known if SciDB authorization\n"++
" (-s) or a prefix (-x) actually works.\n"++
"\n"++
"EXAMPLES\n"++
" To list all currently defined arrays with SciDB authorization required,\n"++
Expand Down Expand Up @@ -281,6 +285,11 @@ internalManual =
" hquery -i coordinator -b 0 -x \"set_namespace('sensor_data');\" \\\n"++
" \"list('arrays');\"\n"++
"\n"++
" To find and project the arrays A, B, C and D to be removed, use\n"++
"\n"++
" hquery -otsv \"project(apply(filter(list('arrays'),regex(name,'A|B|C|D')),\n"++
" remove,'remove('+name+');'),remove);\" | hquery -W\n"++
"\n"++
" To display a synopsis of this internal manual page, use\n"++
"\n"++
" hquery -y\n"++
Expand Down
1 change: 0 additions & 1 deletion src/UtilsUnsafe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import qualified Data.ByteString as B (empty)
import qualified Data.ByteString.Char8 as C (pack)

import Control.Monad (unless)
import Crypto.Hash --()
import Data.Char (toLower)
import Data.Default.Class (def)
import Data.Maybe (fromMaybe,fromJust,isNothing)
Expand Down
29 changes: 16 additions & 13 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,31 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-14.14
resolver: lts-14.27

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# subdirs:
# - auto-update
# - wai
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# using the same syntax as the packages field.
# (e.g., acme-missiles-0.3)
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []
extra-deps: ["BNFC-2.8.2@sha256:dae284c327ed39c28722479081c0bd4a686e0d2bd1dff790b350b8a1742f4036"]
extra-deps:
- BNFC-2.8.3@sha256:606b82fb80afd92ac5059ec76ea96992b23ae30196c511f1bb8e92addbf2edfe,10943

# Override default flag values for local packages and extra-deps
# flags: {}
Expand All @@ -51,7 +54,7 @@ extra-deps: ["BNFC-2.8.2@sha256:dae284c327ed39c28722479081c0bd4a686e0d2bd1dff790
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.9"
# require-stack-version: ">=2.1"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
Expand Down

0 comments on commit b568c3e

Please sign in to comment.