-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
much easier to understand changed: removed -N and -V flags no longer printing number of rows at end removed -p, -N, and -V flags from bf.c
- Loading branch information
1 parent
720d56f
commit 4201cd6
Showing
18 changed files
with
232 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/usr/bin/env @PYTHON_INTERPRETER@ | ||
# This file is part of GUFI, which is part of MarFS, which is released | ||
# under the BSD license. | ||
# | ||
# | ||
# Copyright (c) 2017, Los Alamos National Security (LANS), LLC | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, | ||
# are permitted provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation and/or | ||
# other materials provided with the distribution. | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software without | ||
# specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# | ||
# From Los Alamos National Security, LLC: | ||
# LA-CC-15-039 | ||
# | ||
# Copyright (c) 2017, Los Alamos National Security, LLC All rights reserved. | ||
# Copyright 2017. Los Alamos National Security, LLC. This software was produced | ||
# under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National | ||
# Laboratory (LANL), which is operated by Los Alamos National Security, LLC for | ||
# the U.S. Department of Energy. The U.S. Government has rights to use, | ||
# reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS | ||
# ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR | ||
# ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is | ||
# modified to produce derivative works, such modified software should be | ||
# clearly marked, so as not to confuse it with the version available from | ||
# LANL. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
# OF SUCH DAMAGE. | ||
|
||
|
||
|
||
import argparse | ||
import sys | ||
import subprocess | ||
|
||
import gufi_common | ||
import gufi_config | ||
|
||
def parse_args(argv): | ||
parser = argparse.ArgumentParser('querydbs', description='Query GUFI result dbs') | ||
|
||
parser.add_argument('table_name', | ||
help='name of table in database file to attach; also used for view name: \'v<table_name>\'') | ||
parser.add_argument('SQL', | ||
help='arbitrary SQL executed on view') | ||
|
||
parser.add_argument('db', | ||
nargs='+', | ||
help='path of source database file(s) to add to view') | ||
|
||
parser.add_argument('-d', | ||
type=gufi_common.get_char, | ||
dest='delim', | ||
default='|', | ||
help='delimiter') | ||
|
||
parser.add_argument('--attach-prefix', | ||
metavar='name', | ||
default='querydbs_prefix', | ||
help='name when attaching dbs') | ||
|
||
parser.add_argument('--verbose', '-V', | ||
action='store_true', | ||
help='Show the equivalent shell command passing raw SQL into gufi_sqlite3') | ||
|
||
return parser.parse_args(argv[1:]) | ||
|
||
def run(argv, config_path): | ||
# find and parse the configuration file first | ||
config = gufi_config.Server(config_path) | ||
|
||
args = parse_args(argv) | ||
|
||
attach = [] # ATTACH '<db>' AS <attach_prefix><index>; | ||
select = [] # SELECT * FROM <attach_prefix><index>.<table_name> | ||
|
||
for i, db in enumerate(args.db): | ||
attach_name = '{}{}'.format(args.attach_prefix, i) | ||
attach += ['ATTACH \'{}\' AS {};'.format(db, attach_name)] | ||
select += ['SELECT * FROM {}.{}'.format(attach_name, args.table_name)] | ||
|
||
# CREATE TEMP VIEW v<table_name> AS SELECT * FROM <attach_prefix><index>.<table_name> ... ; | ||
union_all = 'CREATE TEMP VIEW v{} AS '.format(args.table_name) + ' UNION ALL '.join(select) + ';' | ||
|
||
cmd = [config.sqlite3,'-d', args.delim] | ||
sql = attach + [union_all, args.SQL] | ||
stdin = '\n'.join(sql) | ||
|
||
if args.verbose: | ||
print('(') | ||
for line in sql: | ||
print(' echo "{}"'.format(line)) | ||
print(') {} -d "{}"'.format(cmd[0], cmd[2])) | ||
sys.stdout.flush() | ||
|
||
query = subprocess.Popen(cmd, stdin=subprocess.PIPE) # pylint: disable=consider-using-with | ||
query.communicate(stdin.encode()) # block until query finishes | ||
|
||
return query.returncode | ||
|
||
if __name__ == '__main__': | ||
sys.exit(run(sys.argv, gufi_config.PATH)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.