示例#1
0
    def loadConfig(self, config):
        for key in HyriseDriver.DEFAULT_CONFIG.keys():
            assert key in config, "Missing parameter '%s' in %s configuration" % (
                key, self.name)

        self.hyrise_builddir = str(config['hyrise_builddir'])
        self.table_location = str(config['table_location'])
        self.query_directory = str(config['query_location'])
        self.loadQueryfiles(self.query_directory, QUERY_FILES)

        #Print the JSON used for loading the table files into HYRISE and exit
        if config["print_load"]:
            print self.generateTableloadJson()
            sys.exit(-1)

        port = None
        if config.has_key('port'):
            port = str(config['port'])
        else:
            with open(os.path.join(self.hyrise_builddir, 'hyrise_server.port'),
                      'r') as portfile:
                port = portfile.read()

        querylog = config['querylog'] if config['querylog'] != "" else None
        self.conn = HyriseConnection(host=str(config["server_url"]),
                                     port=port,
                                     querylog=querylog)
示例#2
0
    def loadConfig(self, config):
        for key in HyriseDriver.DEFAULT_CONFIG.keys():
            assert key in config, "Missing parameter '%s' in %s configuration" % (
                key, self.name)

        self.database = str(config["database"])
        self.query_location = str(config["queries"])
        port = None
        if config.has_key('port'):
            port = str(config['port'])
        else:
            with open(str(config['portfile']), 'r') as portfile:
                port = portfile.read()

        if config.has_key('querylog'):
            debuglog = config['querylog']
            self.debug = True
        self.conn = HyriseConnection(host=str(config["server_url"]),
                                     port=port,
                                     debuglog=debuglog)

        if config["print_load"]:
            print self.generateTableloadJson()
            sys.exit(-1)

        for query_type, query_dict in QUERY_FILES.iteritems():
            for query_name, filename in query_dict.iteritems():
                with open(
                        os.path.abspath(
                            os.path.join(self.query_location, filename)),
                        'r') as jsonfile:
                    self.queries.setdefault(query_type,
                                            {})[query_name] = jsonfile.read()

        if config["reset"] and os.path.exists(
                os.path.join(self.basepath, self.database)):
            logging.debug("Deleting database '%s'" % self.database)
            for tablename in [
                    'WAREHOUSE.tbl', 'DISTRICT.tbl', 'CUSTOMER.tbl',
                    'HISTORY.tbl', 'ORDER.tbl', 'ORDER_LINE.tbl', 'ITEM.tbl',
                    'STOCK.tbl'
            ]:
                try:
                    os.unlink(
                        os.path.join(self.basepath, self.database, tablename))
                except OSError as e:
                    if e.errno == 2:  #FileNotFound
                        print '{} not found in {}. Skipping.'.format(
                            tablename,
                            os.path.join(self.basepath, self.database))
            for k, v in HEADERS.iteritems():
                filename = os.path.join(self.basepath, self.database,
                                        k + '.tbl')
                with open(filename, 'w') as tblfile:
                    tblfile.write(v)