Erstellen eines Joins auf der Grundlage einer Liste allgemeiner VariablenHallo,
Ich möchte die hart codierten Spaltennamen in diesem Beispiel ersetzen:
dt = dt1 << Join(
With( dt_ref ),
Select(
:result_Rx_RSSI_,
:result_snr_Rx_RSSI_,
:type_,
:rat_,
:trx_,
),
SelectWith( :result_Rx_RSSI_ref, :result_snr_Rx_RSSI_ref, ),
By Matching Columns(
:type_ = :type_,
:rat_ = :rat_,
:trx_ = :trx_,
),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( "merged_results" )
);
mit etwas, das anfängt mit
common_vars = {"type_", "rat_", "trx};
dt1_only_vars = {"result_Rx_RSSI_", "result_snr_Rx_RSSI_"};
dt_ref_only_vars = {"result_Rx_RSSI_ref", "result_snr_Rx_RSSI_ref"};... und dies sollte zum gleichen Ergebnis führen.
Wie mache ich das?
Danke für deine Hilfe!
Re: Erstellen eines Joins basierend auf einer Liste gängiger VariablenVielen Dank! Das ist viel einfacher zu lesen als mein Ansatz.Re: Erstellen eines Joins basierend auf einer Liste gängiger VariablenVielleicht habe ich Ihren Fall zu stark vereinfacht, aber, zu Ihrer Information, das funktioniert auch:
dt1 = NewTable("One",
NewColumn("A", Values([1,2])),
NewColumn("B", Values([3,4])),
NewColumn("K1", Values([5,6])),
NewColumn("K2", Values([7,8]))
);
dt2 = NewTable("Two",
NewColumn("C", Values([9,10])),
NewColumn("D", Values([11,12])),
NewColumn("K2", Values([5,6])),
NewColumn("K1", Values([7,8]))
);
dt1KeyCols = {"K1", "K2"};
dt2KeyCols = {"K2", "K1"};
dtFinal = dt1 << Join(
With(dt2),
By Matching Columns( dt1KeyCols = dt2KeyCols ),
Output Table( "Joined" )
);Re: Erstellen eines Joins basierend auf einer Liste gängiger VariablenDanke für die Rückmeldung.
So habe ich es dank dieses Blogeintrags gelöst:
http://www.pega-analytics.co.uk/blog/handling-lists-of-columns/
common_vars = {"type_", "rat_", "trx"};
dt1_only_vars = {"result_Rx_RSSI_", "result_snr_Rx_RSSI_"};
dt_ref_only_vars = {"result_Rx_RSSI_ref", "result_snr_Rx_RSSI_ref"};
col_names = dt1_only_vars || common_vars;
match_str = "";
For( i = 1, i <= N Items( common_vars ), i++,
match_col_name = common_vars[i];
mstr = Eval Insert( ":^match_col_name^ = :^match_col_name^," );
match_str = match_str || mstr;
);
// this is UGLY but I do not know any other way (yet?)
dt_str = Eval Insert(
"dt = dt1 << Join(
With( dt_ref ),
Select(
Eval( col_names )
),
SelectWith( Eval(dt_ref_only_vars) ),
By Matching Columns(
^match_str^
),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( \!"merged_results\!" ));"
);
Eval( Parse( dt_str ) );Re: Erstellen eines Joins basierend auf einer Liste gängiger VariablenHallo Alex!
Zunächst einmal vielen Dank, dass Sie Ihr Beispiel viel schwieriger eingeben als Ihre ursprüngliche Frage!
Ich weiß nicht, warum Sie eine Liste mit allgemeinen Variablen für einen Join verwenden möchten. Ändern sich die Variablen? Wären Benutzerdialoge nützlich? Ihre Gründe können die Richtung beeinflussen, in die Sie gehen sollten.
Nehmen wir jedoch an, dass jemand die "Referenzwerte" in Ihrem No Score-Dataset pflegen muss, und es wäre hilfreich, aufzuzeichnen, wo No Country-Dataset-Werte keine No Score-Werte haben, was darauf hindeuten würde, dass ein Left Outer Join vorliegt angemessen.
dt_recombined = Query(
Table( dt_no_country, "t1" ),
Table( dt_no_score, "t2" ),
"SELECT t1.Name AS [Name from Table1], t1.Score, t1.[100m], t1.[Long Jump], t1.[Shot Put], t1.[High Jump], t1.[400m], t1.[100m hurdles], t1.Discus, t1.[Pole Vault], t1.Javelin, t1.[1500m],
t2.Name AS [Name from Table2], t2.Country
FROM t1
LEFT OUTER JOIN t2
ON ( t1.Name = t2.Name and
t1.[100m] = t2.[100m] and
t1.[Long Jump] = t2.[Long Jump] and
t1.[Shot Put] = t2.[Shot Put] and
t1.[High Jump] = t2.[High Jump] and
t1.[400m] = t2.[400m] and
t1.[100m hurdles] = t2.[100m hurdles] and
t1.Discus = t2.Discus and
t1.[Pole Vault] = t2.[Pole Vault] and
t1.Javelin = t2.Javelin and
t1.[1500m] = t2.[1500m] ) " ); Wenn Sie wirklich brauchen, können Sie die Variablen leicht in Ausdrücke umwandeln, die Sie beliebig auswerten und ersetzen können.
Re: Erstellen eines Joins basierend auf einer Liste gängiger Variablendt = Open( "$SAMPLE_DATA/Decathlon.jmp" );
dt_no_score = dt << Subset(
Output Table( "Decathlon_no_score" ),
All rows,
columns(
:Name,
:Country,
:Name( "100m" ),
:Long Jump,
:Shot Put,
:High Jump,
:Name( "400m" ),
:Name( "100m hurdles" ),
:Discus,
:Pole Vault,
:Javelin,
:Name( "1500m" )
)
);
dt_no_country = dt << Subset(
Output Table( "Decathlon_no_country" ),
All rows,
columns(
:Name,
:Score,
:Name( "100m" ),
:Long Jump,
:Shot Put,
:High Jump,
:Name( "400m" ),
:Name( "100m hurdles" ),
:Discus,
:Pole Vault,
:Javelin,
:Name( "1500m" )
)
);
dt_recombined = dt_no_country << Join(
With( dt_no_score ),
Select(
:Name,
:Score,
:Name( "100m" ),
:Long Jump,
:Shot Put,
:High Jump,
:Name( "400m" ),
:Name( "100m hurdles" ),
:Discus,
:Pole Vault,
:Javelin,
:Name( "1500m" )
),
SelectWith( :Country ),
By Matching Columns(
:Name = :Name,
:Name( "100m" ) = :Name( "100m" ),
:Long Jump = :Long Jump,
:Shot Put = :Shot Put,
:High Jump = :High Jump,
:Name( "400m" ) = :Name( "400m" ),
:Name( "100m hurdles" ) = :Name( "100m hurdles" ),
:Discus = :Discus,
:Pole Vault = :Pole Vault,
:Javelin = :Javelin,
:Name( "1500m" ) = :Name( "1500m" )
),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
)
Re: Erstellen eines Joins basierend auf einer Liste gängiger VariablenHallo Alex!
Dafür gibt es viele Möglichkeiten.
Können Sie einige (ggf. anonymisierte) dt1- und dt_ref-Datensätze posten?