Named column equi-joins

Hi,

given two keyed tables, both with different keys, is it possible to join based on named columns, where column names may differ? Here’s a slightly verbose example:

q)balances:([Account:SmithJones;Currency:USDEUR]Balance:(0.10f;0.20f))q)balancesAccount Currency| Balance----------------| -------Smith USD | 0.1Jones EUR | 0.2q)offers:([Account:SmithSmithJones;Sequence:(0;1;0)]TakerGetsAmount:(0.01;0.011;0.12);TakerGetsCurrency:USDUSDEUR;TakerPaysAmount:(0.015;0.016;0.017);TakerPaysCurrency:EURUSDUSD)q)offersAccount Sequence| TakerGetsAmount TakerGetsCurrency TakerPaysAmount TakerPaysCurrency----------------| -------------------------------------------------------------------Smith 0 | 0.01 USD 0.015 EURSmith 1 | 0.011 USD 0.016 USDJones 0 | 0.12 EUR 0.017 USDq)ej[AccountTakerGetsCurrency;offers;balances]k){x,:();y[&#:‘i],’(x_z)(!0),/i:(=x#z:0!z)x#y:0!y}'TakerGetsCurrency#AccountTakerGetsCurrency+AccountCurrencyBalance!(SmithJones;USDEUR;0.1 0.2)q.q))

I’d like to get the available balance for each offer by using a join key of Account and TakerGetsCurrency, but the join fails because TakerGetsCurrency in the offers table and Currency in the balances table have different names. Thanks for any help!

Cheers,

Donovan.

You can use xcol:
        ej[AccountCurrency;AccountSequenceTakerGetsAmountCurrency xcol offers; balances]

xcol is cheap, i.e. it won’t create a copy the underlying table’s data:

q)\ts t:(k: 1000000?`4; v: 1000000?10000)

137 16778096j

q)\ts \ts KeyValue xcol t

0j, 624j

Igor, that’s perfect. Thanks again!