schema: {table_name: [field_name]} :param cursor: :return:
(self)
| 204 | return self.pgsql_cost_estimation(sql) |
| 205 | |
| 206 | def compute_table_schema(self): |
| 207 | """ |
| 208 | schema: {table_name: [field_name]} |
| 209 | :param cursor: |
| 210 | :return: |
| 211 | """ |
| 212 | |
| 213 | if self.args.dbtype == 'postgresql': |
| 214 | # cur_path = os.path.abspath('.') |
| 215 | # tpath = cur_path + '/sampled_data/'+dbname+'/schema' |
| 216 | sql = 'SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\';' |
| 217 | success, res = self.execute_sql(sql) |
| 218 | #print("======== tables", res) |
| 219 | if success == 1: |
| 220 | tables = res |
| 221 | schema = {} |
| 222 | for table_info in tables: |
| 223 | table_name = table_info[0] |
| 224 | sql = 'SELECT column_name, data_type FROM information_schema.columns WHERE table_name = \'' + table_name + '\';' |
| 225 | success, res = self.execute_sql(sql) |
| 226 | #print("======== table columns", res) |
| 227 | columns = res |
| 228 | schema[table_name] = [] |
| 229 | for col in columns: |
| 230 | |
| 231 | ''' compute the distinct value ratio of the column |
| 232 | |
| 233 | if transfer_field_type(col[1], self.args.dbtype) == DataType.VALUE.value: |
| 234 | sql = 'SELECT count({}) FROM {};'.format(col[0], table_name) |
| 235 | success, res = self.execute_sql(sql) |
| 236 | print("======== column rows", res) |
| 237 | num = res |
| 238 | if num[0][0] != 0: |
| 239 | schema[table_name].append(col[0]) |
| 240 | ''' |
| 241 | |
| 242 | #schema[table_name].append("column {} is of {} type".format(col[0], col[1])) |
| 243 | schema[table_name].append("{}".format(col[0])) |
| 244 | ''' |
| 245 | with open(tpath, 'w') as f: |
| 246 | f.write(str(schema)) |
| 247 | ''' |
| 248 | #print(schema) |
| 249 | return schema |
| 250 | |
| 251 | else: |
| 252 | logging.error('pgsql_cost_estimation Fails!') |
| 253 | return 0 |
| 254 | |
| 255 | def simulate_index(self, index): |
| 256 | #table_name = index.table() |
no test coverage detected