| 1055 | | # distinct, which was a speed issue more than anything. Grr. |
|---|
| 1056 | | raise ValueError(u"The following query cannot be reliably " |
|---|
| 1057 | | u"returned from this data source.", |
|---|
| 1058 | | u"distinct()", cls, fields, expr) |
|---|
| 1059 | | |
|---|
| 1060 | | data, columns = self.fetch(sql) |
|---|
| 1061 | | actualTypes = [x[1] for x in columns] |
|---|
| 1062 | | expectedTypes = [cls.property_type(x) for x in fields] |
|---|
| 1063 | | |
|---|
| 1064 | | coerce = self.fromAdapter.coerce |
|---|
| 1065 | | # Must use inner tuples for hashability in Sandbox.distinct() |
|---|
| 1066 | | return [tuple([coerce(val, actualTypes[i], expectedTypes[i]) |
|---|
| 1067 | | for i, val in enumerate(row)]) |
|---|
| 1068 | | for row in data] |
|---|
| | 1055 | # distinct, which was a speed issue more than anything. |
|---|
| | 1056 | warnings.warn("The requested distinct() query for %s Units " |
|---|
| | 1057 | "cannot produce perfect SQL with a %s datasource. " |
|---|
| | 1058 | "It may take an absurd amount of time to run, " |
|---|
| | 1059 | "since each unit must be fully-formed. %s" |
|---|
| | 1060 | % (cls.__name__, self.__class__.__name__, expr)) |
|---|
| | 1061 | distvals = {} |
|---|
| | 1062 | for unit in self.recall(cls, expr): |
|---|
| | 1063 | # Must use inner tuples for hashability in Sandbox.distinct() |
|---|
| | 1064 | val = tuple([getattr(unit, f) for f in fields]) |
|---|
| | 1065 | distvals[val] = None |
|---|
| | 1066 | return distvals.keys() |
|---|
| | 1067 | else: |
|---|
| | 1068 | data, columns = self.fetch(sql) |
|---|
| | 1069 | actualTypes = [x[1] for x in columns] |
|---|
| | 1070 | expectedTypes = [cls.property_type(x) for x in fields] |
|---|
| | 1071 | |
|---|
| | 1072 | coerce = self.fromAdapter.coerce |
|---|
| | 1073 | # Must use inner tuples for hashability in Sandbox.distinct() |
|---|
| | 1074 | return [tuple([coerce(val, actualTypes[i], expectedTypes[i]) |
|---|
| | 1075 | for i, val in enumerate(row)]) |
|---|
| | 1076 | for row in data] |
|---|