MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / corresponding_column

Method corresponding_column

lib/sqlalchemy/sql/base.py:1917–2021  ·  view source on GitHub ↗

Given a :class:`_expression.ColumnElement`, return the exported :class:`_expression.ColumnElement` object from this :class:`_expression.ColumnCollection` which corresponds to that original :class:`_expression.ColumnElement` via a common ancestor column.

(
        self, column: _COL, require_embedded: bool = False
    )

Source from the content-addressed store, hash-verified

1915 pi[eps_col].add(metrics)
1916
1917 def corresponding_column(
1918 self, column: _COL, require_embedded: bool = False
1919 ) -> Optional[Union[_COL, _COL_co]]:
1920 """Given a :class:`_expression.ColumnElement`, return the exported
1921 :class:`_expression.ColumnElement` object from this
1922 :class:`_expression.ColumnCollection`
1923 which corresponds to that original :class:`_expression.ColumnElement`
1924 via a common
1925 ancestor column.
1926
1927 :param column: the target :class:`_expression.ColumnElement`
1928 to be matched.
1929
1930 :param require_embedded: only return corresponding columns for
1931 the given :class:`_expression.ColumnElement`, if the given
1932 :class:`_expression.ColumnElement`
1933 is actually present within a sub-element
1934 of this :class:`_expression.Selectable`.
1935 Normally the column will match if
1936 it merely shares a common ancestor with one of the exported
1937 columns of this :class:`_expression.Selectable`.
1938
1939 .. seealso::
1940
1941 :meth:`_expression.Selectable.corresponding_column`
1942 - invokes this method
1943 against the collection returned by
1944 :attr:`_expression.Selectable.exported_columns`.
1945
1946 .. versionchanged:: 1.4 the implementation for ``corresponding_column``
1947 was moved onto the :class:`_expression.ColumnCollection` itself.
1948
1949 """
1950 # TODO: cython candidate
1951
1952 # don't dig around if the column is locally present
1953 if column in self._colset:
1954 return column
1955
1956 selected_intersection, selected_metrics = None, None
1957 target_set = column.proxy_set
1958
1959 pi = self._proxy_index
1960 if not pi:
1961 self._init_proxy_index()
1962
1963 for current_metrics in (
1964 mm for ts in target_set if ts in pi for mm in pi[ts]
1965 ):
1966 if not require_embedded or current_metrics.embedded(target_set):
1967 if selected_metrics is None:
1968 # no corresponding column yet, pick this one.
1969 selected_metrics = current_metrics
1970 continue
1971
1972 current_intersection = target_set.intersection(
1973 current_metrics.column._expanded_proxy_set
1974 )

Callers

nothing calls this directly

Calls 7

_init_proxy_indexMethod · 0.95
sumClass · 0.85
embeddedMethod · 0.80
_uncached_proxy_listMethod · 0.80
shares_lineageMethod · 0.80
intersectionMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected