Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

# This file is part of daf_butler. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

__all__ = ("QueryBuilder",) 

 

import logging 

from abc import ABC, abstractmethod 

from sqlalchemy.sql import and_, or_, not_, literal 

 

from ..core import DimensionJoin, DimensionSet 

from ..exprParser import ParserYacc, TreeVisitor 

from .resultColumnsManager import ResultColumnsManager 

 

_LOG = logging.getLogger(__name__) 

 

 

class _ClauseVisitor(TreeVisitor): 

"""Implement TreeVisitor to convert user expression into SQLAlchemy 

clause. 

 

Parameters 

---------- 

queryBuilder: `QueryBuilder` 

Query builder object the new visitor is to be a helper for. 

""" 

 

45 ↛ exit,   45 ↛ exit,   45 ↛ exit3 missed branches: 1) line 47 didn't finish the lambda on line 47, 2) line 46 didn't finish the lambda on line 46, 3) line 45 didn't run the lambda on line 45 unaryOps = {"NOT": lambda x: not_(x), 

"+": lambda x: +x, 

"-": lambda x: -x} 

"""Mapping or unary operator names to corresponding functions""" 

 

50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit,   50 ↛ exit13 missed branches: 1) line 62 didn't finish the lambda on line 62, 2) line 61 didn't finish the lambda on line 61, 3) line 60 didn't finish the lambda on line 60, 4) line 59 didn't finish the lambda on line 59, 5) line 58 didn't finish the lambda on line 58, 6) line 57 didn't finish the lambda on line 57, 7) line 56 didn't finish the lambda on line 56, 8) line 55 didn't finish the lambda on line 55, 9) line 54 didn't finish the lambda on line 54, 10) line 53 didn't finish the lambda on line 53, 11) line 52 didn't finish the lambda on line 52, 12) line 51 didn't finish the lambda on line 51, 13) line 50 didn't run the lambda on line 50 binaryOps = {"OR": lambda x, y: or_(x, y), 

"AND": lambda x, y: and_(x, y), 

"=": lambda x, y: x == y, 

"!=": lambda x, y: x != y, 

"<": lambda x, y: x < y, 

"<=": lambda x, y: x <= y, 

">": lambda x, y: x > y, 

">=": lambda x, y: x >= y, 

"+": lambda x, y: x + y, 

"-": lambda x, y: x - y, 

"*": lambda x, y: x * y, 

"/": lambda x, y: x / y, 

"%": lambda x, y: x % y} 

"""Mapping or binary operator names to corresponding functions""" 

 

def __init__(self, queryBuilder): 

self.queryBuilder = queryBuilder 

 

def visitNumericLiteral(self, value, node): 

# Docstring inherited from TreeVisitor.visitNumericLiteral 

# Convert string value into float or int 

try: 

value = int(value) 

except ValueError: 

value = float(value) 

return literal(value) 

 

def visitStringLiteral(self, value, node): 

# Docstring inherited from TreeVisitor.visitStringLiteral 

return literal(value) 

 

def visitRangeLiteral(self, start, stop, stride, node): 

# Docstring inherited from TreeVisitor.visitRangeLiteral 

 

# Just return a triple and let parent clauses handle it, 

# stride can be None which means the same as 1 

return (start, stop, stride or 1) 

 

def visitIdentifier(self, name, node): 

# Docstring inherited from TreeVisitor.visitIdentifier 

table, sep, column = name.partition('.') 

if column: 

selectable = self.queryBuilder.findSelectableByName(table) 

if selectable is None: 

raise ValueError(f"No table or clause with name '{table}' in this query.") 

else: 

column = table 

selectable = self.queryBuilder.findSelectableForLink(column) 

if selectable is None: 

raise ValueError(f"No table or clause providing link '{column}' in this query.") 

try: 

return selectable.columns[column] 

except KeyError as err: 

raise ValueError(f"No column '{column}' found.") from err 

 

def visitUnaryOp(self, operator, operand, node): 

# Docstring inherited from TreeVisitor.visitUnaryOp 

func = self.unaryOps.get(operator) 

if func: 

return func(operand) 

else: 

raise ValueError(f"Unexpected unary operator `{operator}' in `{node}'.") 

 

def visitBinaryOp(self, operator, lhs, rhs, node): 

# Docstring inherited from TreeVisitor.visitBinaryOp 

func = self.binaryOps.get(operator) 

if func: 

return func(lhs, rhs) 

else: 

raise ValueError(f"Unexpected binary operator `{operator}' in `{node}'.") 

 

def visitIsIn(self, lhs, values, not_in, node): 

# Docstring inherited from TreeVisitor.visitIsIn 

 

# `values` is a list of literals and ranges, range is represented 

# by a tuple (start, stop, stride). We need to transform range into 

# some SQL construct, simplest would be to generate a set of literals 

# and add it to the same list but it could become too long. What we 

# do here is to introduce some large limit on the total number of 

# items in IN() and if range exceeds that limit then we do something 

# like: 

# 

# X IN (1, 2, 3) 

# OR 

# (X BETWEEN START AND STOP AND MOD(X, STRIDE) = MOD(START, STRIDE)) 

# 

# or for NOT IN case 

# 

# NOT (X IN (1, 2, 3) 

# OR 

# (X BETWEEN START AND STOP 

# AND MOD(X, STRIDE) = MOD(START, STRIDE))) 

 

max_in_items = 1000 

 

# split the list into literals and ranges 

literals, ranges = [], [] 

for item in values: 

if isinstance(item, tuple): 

ranges.append(item) 

else: 

literals.append(item) 

 

clauses = [] 

for start, stop, stride in ranges: 

count = (stop - start + 1) // stride 

if len(literals) + count > max_in_items: 

# X BETWEEN START AND STOP 

# AND MOD(X, STRIDE) = MOD(START, STRIDE) 

expr = lhs.between(start, stop) 

if stride != 1: 

expr = and_(expr, (lhs % stride) == (start % stride)) 

clauses.append(expr) 

else: 

# add all values to literal list, stop is inclusive 

literals += [literal(value) for value in range(start, stop+1, stride)] 

 

if literals: 

# add IN() in front of BETWEENs 

clauses.insert(0, lhs.in_(literals)) 

 

expr = or_(*clauses) 

if not_in: 

expr = not_(expr) 

 

return expr 

 

def visitParens(self, expression, node): 

# Docstring inherited from TreeVisitor.visitParens 

return expression.self_group() 

 

 

class QueryBuilder(ABC): 

"""Helper class for constructing a query that joins together several 

related `Dimension` and `DimensionJoin` tables. 

 

`QueryBuilder` and its subclasses are responsible for ensuring that tables 

and views that represent `Dimension` and `DatasetType` objects are 

properly joined into and selected from in a query. They do not in general 

take responsibility for ensuring that a self-consistent or useful set of 

`Dimension` and `DatasetType` tables/views are included in the query, but 

do provide special `classmethod` constructors that guarantee this for 

certain common cases. 

 

Parameters 

---------- 

registry : `SqlRegistry` 

Registry instance the query is being run against. 

fromClause : `sqlalchemy.sql.expression.FromClause`, optional 

Initial FROM clause for the query. 

whereClause : SQLAlchemy boolean expression, optional 

Expression to use as the initial WHERE clause. 

""" 

 

def __init__(self, registry, *, fromClause=None, whereClause=None): 

self.registry = registry 

self._resultColumns = ResultColumnsManager(self.registry) 

self._fromClause = fromClause 

self._whereClause = whereClause 

self._selectablesForDimensionElements = {} 

self._elementsCache = None 

 

@classmethod 

def fromDimensions(cls, registry, dimensions, addResultColumns=True): 

"""Construct a query for a complete `DimensionGraph`. 

 

This ensures that all `DimensionJoin` tables that relate the given 

dimensions are correctly included. 

 

Parameters 

---------- 

registry : `SqlRegistry` 

Registry instance the query is being run against. 

dimensions : `DimensionGraph` 

The full set of dimensions to be included in the query. 

addResultColumns : `bool` 

If `True` (default), automatically include all link columns for 

the given dimensions in the SELECT clause for the query. 

""" 

self = cls(registry) 

for dimension in dimensions: 

self.joinDimensionElement(dimension) 

for join in dimensions.joins(summaries=False): 

if not join.asNeeded: 

self.joinDimensionElement(join) 

if addResultColumns: 

for link in dimensions.links(): 

self.selectDimensionLink(link) 

return self 

 

@property 

def fromClause(self): 

"""The current FROM clause for the in-progress query 

(`sqlalchemy.sql.FromClause`). 

 

The FROM clause cannot be modified via this property; use `join` 

instead. 

""" 

return self._fromClause 

 

@property 

def whereClause(self): 

"""The current WHERE clause for the in-progress query (SQLAlchemy 

column expression). 

 

The WHERE clause cannot be modified via this property; use 

`whereSqlExpressoin` instead. 

""" 

return self._whereClause 

 

@property 

def resultColumns(self): 

"""The helper object that manages the SELECT clause of the query 

(`ResultColumnsManager`). 

""" 

return self._resultColumns 

 

def join(self, selectable, links, isOuter=False): 

"""Join a new selectable (table, view, or subquery) into the query. 

 

Parameters 

---------- 

selectable : `sqlalchemy.sql.FromClause` 

SQLAlchemy representation of a table, view, or subquery to be 

joined into the the query. 

links : iterable of `str` 

The dimension link values (i.e. data ID keys) that are columns 

for ``selectable``; any of these that are already present on any 

other selectable in the query will be used in the ON expression 

for this join. 

isOuter : `bool` 

If `True`, perform a LEFT OUTER JOIN instead of a regular (INNER) 

JOIN. 

""" 

if self.fromClause is None: 

self._fromClause = selectable 

return 

joinOn = [] 

for link in links: 

selectableAlreadyIncluded = self.findSelectableForLink(link) 

if selectableAlreadyIncluded is not None: 

joinOn.append(selectableAlreadyIncluded.columns[link] == selectable.columns[link]) 

if joinOn: 

self._fromClause = self.fromClause.join(selectable, and_(*joinOn), isouter=isOuter) 

else: 

# New table is completely unrelated to all already-included 

# tables. We need a cross join here but SQLAlchemy does not have 

# specific method for that. Using join() without `onclause` will 

# try to join on FK and will raise an exception for unrelated 

# tables, so we have to use `onclause` which is always true. 

self._fromClause = self.fromClause.join(selectable, literal(True) == literal(True), 

isouter=isOuter) 

 

def whereSqlExpression(self, sqlExpression, op=and_): 

"""Add a SQL expression to the query's WHERE clause. 

 

Parameters 

---------- 

sqlExpression: `sqlalchemy.sql.ColumnElement` 

SQLAlchemy boolean column expression. 

op : `sqlalchemy.sql.operator` 

Binary operator to use if a WHERE expression already exists. 

""" 

if self.whereClause is None: 

self._whereClause = sqlExpression 

else: 

self._whereClause = op(self.whereClause, sqlExpression) 

 

def whereParsedExpression(self, expression, op=and_): 

"""Add a parsed dimension expression to the query's WHERE clause. 

 

Parameters 

---------- 

expression : `str` 

String expression involving dimensions. 

op : `sqlalchemy.sql.operator` 

Binary operator to use if a WHERE expression already exists. 

""" 

try: 

parser = ParserYacc() 

expression = parser.parse(expression) 

except Exception as exc: 

raise ValueError(f"Failed to parse user expression `{expression}'") from exc 

if expression: 

visitor = _ClauseVisitor(self) 

sqlExpression = expression.visit(visitor) 

_LOG.debug("where from expression: %s", sqlExpression) 

self.whereSqlExpression(sqlExpression, op=op) 

 

def whereDataId(self, dataId, op=and_): 

"""Add a dimension constraint from a data ID to the query's WHERE 

clause. 

 

All data ID values that correspond to dimension values already included 

in the query will be used in the constraint; any others will be 

ignored. 

 

Parameters 

---------- 

dataId : `DataId` or `dict` 

Data ID to require (at least partial) dimension equality with. 

op : `sqlalchemy.sql.operator` 

Binary operator to use if a WHERE expression already exists. 

 

Returns 

------- 

links : `set` of `str` 

The data ID keys actually used in the constraint. 

""" 

links = set() 

terms = [] 

for key, value in dataId.items(): 

selectable = self.findSelectableForLink(key) 

if selectable is not None: 

links.add(key) 

terms.append(selectable.columns[key] == value) 

if terms: 

self.whereSqlExpression(and_(*terms), op=op) 

return links 

 

def selectDimensionLink(self, link): 

"""Add a dimension link column to the SELECT clause of the query. 

 

Parameters 

---------- 

link : `str` 

Dimension link name (i.e. data ID key) to select. 

""" 

selectable = self.findSelectableForLink(link) 

if selectable is None: 

raise ValueError(f"No table involving link {link} in query.") 

self.resultColumns.addDimensionLink(selectable, link) 

 

def build(self, whereSql=None): 

"""Return the full SELECT query. 

 

Parameters 

---------- 

whereSql 

An additional SQLAlchemy boolean column expression to include 

in the query. Unlike the `whereSqlExpression` method, this 

does not modify the builder itself. 

 

Returns 

------- 

query: `sqlalchemy.sql.Select` 

Completed query that combines the FROM clause represented by 

`fromClause`, the WHERE clause represented by `whereClause`, 

and the SELECT clause managed by `resultColumns`. 

""" 

query = self.resultColumns.selectFrom(self.fromClause) 

if self._whereClause is not None: 

query = query.where(self._whereClause) 

if whereSql is not None: 

query = query.where(whereSql) 

if _LOG.isEnabledFor(logging.DEBUG): 

try: 

compiled = query.compile(bind=self.registry._connection.engine, 

compile_kwargs={"literal_binds": True}) 

except AttributeError: 

# Workaround apparent SQLAlchemy bug that sometimes treats a 

# list as if it were a string. 

compiled = str(query) 

_LOG.debug("building query: %s", compiled) 

return query 

 

def __str__(self): 

query = self.build() 

try: 

compiled = str(query.compile(bind=self.registry._connection.engine, 

compile_kwargs={"literal_binds": True})) 

except AttributeError: 

# Workaround apparent SQLAlchemy bug that sometimes treats a 

# list as if it were a string. 

compiled = str(query) 

return compiled 

 

def execute(self, whereSql=None, **kwds): 

"""Build and execute the query, iterating over result rows. 

 

Parameters 

---------- 

whereSql 

An additional SQLAlchemy boolean column expression to include 

in the query. Unlike the `whereSqlExpression` method, this 

does not modify the builder itself. 

kwds 

Additional keyword arguments forwarded to `convertResultRow`. 

 

Yields 

------ 

result 

Objects of the type returned by `convertResultRow`. 

 

Notes 

----- 

Query rows that include disjoint regions are automatically filtered 

out. 

""" 

query = self.build(whereSql=whereSql) 

results = self.registry._connection.execute(query) 

total = 0 

count = 0 

for row in results: 

total += 1 

managed = self.resultColumns.manageRow(row=row) 

if managed.areRegionsDisjoint(): 

continue 

count += 1 

yield self.convertResultRow(managed, **kwds) 

_LOG.debug("Total %d rows in result set, %d after region filtering", total, count) 

 

def executeOne(self, whereSql=None, **kwds): 

"""Build and execute the query, returning a single result row. 

 

Parameters 

---------- 

whereSql 

An additional SQLAlchemy boolean column expression to include 

in the query. Unlike the `whereSqlExpression` method, this 

does not modify the builder itself. 

kwds 

Additional keyword arguments forwarded to `convertResultRow`. 

 

Returns 

------- 

result 

A single object of the type returned by `convertResultRow`, or 

`None` if the query generated no results. 

 

Notes 

----- 

A query row that include disjoint regions is filtered out, resulting 

in `None` being returned. 

""" 

query = self.build(whereSql=whereSql) 

results = self.registry._connection.execute(query) 

for row in results: 

managed = self.resultColumns.manageRow(row) 

if managed is None or managed.areRegionsDisjoint(): 

continue 

return self.convertResultRow(managed, **kwds) 

return None 

 

def getIncludedDimensionElements(self): 

"""Return the set of all `DimensionElement` objects explicitly 

included in the query. 

 

Returns 

------- 

dimensions : `DimensionSet` 

All `Dimension` and `DimensionJoin` objects represented in the 

query. 

""" 

if self._elementsCache is None: 

self._elementsCache = DimensionSet(self.registry.dimensions, 

self._selectablesForDimensionElements.keys()) 

return self._elementsCache 

 

def joinDimensionElement(self, element): 

"""Add a table or view for a `DimensionElement` to the query. 

 

Tables can be added in any order, and repeated calls with the same 

element are safe no-ops. Tables are automatically joined to any other 

tables already in the query with which they share any dependency 

relationship, but callers are responsible for making sure any such 

tables are added (and in the right order, in contexts where that 

matters). 

 

Attempting to add a table for a `DimensionElement` that does not have 

a direct in-database representation (such as the "skypix" `Dimension`) 

is also a safe no-op. 

 

Parameters 

---------- 

element : `DimensionElement` 

`Dimension` or `DimensionJoin` associated with the table or view 

to be added. 

 

Returns 

------- 

table : `sqlalchemy.FromClause` or `None` 

SQLAlchemy object representing the table or view added, or 

`None` if there is no table for the given element. 

""" 

table = self._selectablesForDimensionElements.get(element) 

if table is None: 

# Table isn't already in the output query, see if we can add it. 

table = self.registry._schema.tables.get(element.name) 

if table is None: 

# This element doesn't have an associated table. 

return None 

# Invalidate accessor cache, since we're about to mutate self. 

self._elementsCache = None 

# We found a table, add it to the FROM clause. 

self.join(table, element.links(implied=True)) 

# Now that we've updated self.fromClause, record that we have a 

# table for this element in the query. 

self._selectablesForDimensionElements[element] = table 

# Spatial joins need extra refinement; see if this is one. 

if isinstance(element, DimensionJoin): 

lhsHolder = self.registry.dimensions.extract(element.lhs).getRegionHolder() 

rhsHolder = self.registry.dimensions.extract(element.rhs).getRegionHolder() 

if lhsHolder is not None and rhsHolder is not None: 

# This is a spatial join, but the database only knows 

# about dimension entries that *might* overlap, and can't 

# conclusively state when they do. That means we need to 

# filter the query in Python later, and to do that we need 

# to include the regions of those dimensions in the query 

# results. First we make sure the tables that provide 

# those regions are in the query. Note that this does 

# nothing and returns None for skypix, but that's okay 

# because ResultColumnsManager knows to handle that case 

# specially. 

lhsTable = self.joinDimensionElement(lhsHolder) 

rhsTable = self.joinDimensionElement(rhsHolder) 

self.resultColumns.addRegion(lhsTable, lhsHolder) 

self.resultColumns.addRegion(rhsTable, rhsHolder) 

return table 

 

def findSelectableForLink(self, link): 

"""Return a selectable (table, view, or subquery) already in the query 

that contains a column corresponding to the given dimension link, or 

`None` if no such selectable exists. 

 

If multiple selectables can provide the given link, which one is 

returned is unspecified, but the returned selectable is guaranteed 

to not to have been included with an outer join. 

 

This method should be reimplemented by subclasses by delegating to 

``super()`` first and returning its result if not `None`. 

 

Parameters 

---------- 

link : `str` 

Dimension link name (i.e. data ID key). 

 

Returns 

------- 

selectable : `sqlalchemy.sql.FromClause` or `None` 

A table, view, or subquery that contains the given link column, or 

`None` if one was not found. 

""" 

for element in self.registry.dimensions.withLink(link): 

selectable = self._selectablesForDimensionElements.get(element) 

if selectable is not None: 

return selectable 

return None 

 

def findSelectableByName(self, name): 

"""Return the selectable already in the query with the given name, or 

`None` if no such selectable exists. 

 

This method should be reimplemented by subclasses by delegating to 

``super()`` first and returning its result if not `None`. 

 

Returns 

------- 

selectable : `sqlalchemy.sql.FromClause` or `None` 

A table, view, or subquery with the given name, or `None` if one 

was not found. 

""" 

element = self.getIncludedDimensionElements().get(name) 

if element is None: 

return None 

return self._selectablesForDimensionElements[element] 

 

@abstractmethod 

def convertResultRow(self, managed, **kwds): 

"""Convert a query result row to the type appropriate for this 

`QueryBuilder`. 

 

This method is a customization point for `execute` that must be 

implemented by subclasses. Other code should generally not need 

to call it directly. 

 

Parameters 

---------- 

managed : `ResultColumnsManager.ManagedRow` 

Intermediate row object to convert. 

kwds : 

Additional keyword arguments defined by subclasses. 

 

Returns 

------- 

result 

An object that corresponds to a single query result row, 

with type defined by the subclass implementation. 

""" 

raise NotImplementedError("Must be implemented by subclasses.")