Aggiornamento tabella con righe getCiao,
Ho due tabelle con > 50k righe e 5 -10 colonne e voglio aggiornare la prima tabella (dt1) con i valori della seconda tabella (dt2). Non voglio usare i loop perché potrebbe volerci molto tempo con righe> 50k. La funzione di "aggiornamento" JSL funziona bene, ma ho bisogno anche delle righe abbinate in dt2 per un ulteriore utilizzo.
Per mostrare cosa intendo ho usato l'esempio "update" da "script index" e ho aggiunto il nome MIKE con altezza, peso, rango e codice. Ho bisogno di un elenco con il numero di righe delle righe abbinate. Per quell'esempio sarebbe {1, 2, 3} perché MIKE non esiste in dt1.
Names Default To Here( 1 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = New Table( "Little Class",
Add Rows( 3 ),
New Column( "name", Character, Nominal, Set Values( {"KATIE", "ALFRED", "HENRY", "MIKE"} ) ),
New Column( "height", Continuous, Set Values( [999, 999, 999, 111] ) ),
New Column( "weight", Continuous, Set Values( [999, 999, 999, 111] ) ),
New Column( "RANK", Continuous, Set Values( [3, 1, 2, 9] ) ),
New Column( "CODE", Continuous, Set Values( [0, 1, 1, 8] ) )
);
dt1 << Update(
With( Data Table( "Little Class" ) ),
Match Columns( :name = :name ),
Add columns from Update table( {:RANK} ),
Replace columns in Main Table( {:height} )
);Grazie
Re: Aggiornamento tabella con get righeGrazie, ho provato questo approccio ma per più di 50.000 righe ci vorrà troppo tempo. Per i tavoli più piccoli funziona bene.Re: Aggiornamento tabella con get righeGrazie, funziona bene, anche per un numero elevato di righe.Re: Aggiornamento tabella con get righeTi suggerisco di utilizzare un join invece dell'aggiornamento.Se impostato correttamente, funzionerà come l'aggiornamento, ma aggiungerà nuove righe.Ti fornirà anche una colonna che indicherà quali righe sono state aggiunte.
Lo svantaggio è che crea una nuova tabella di dati, ma con un paio di istruzioni, che possono essere gestite, e sembrerà proprio come se fosse stato eseguito un aggiornamento.Guarda il codice qui sotto:
Names Default To Here( 1 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = New Table( "Little Class",
Add Rows( 3 ),
New Column( "name", Character, Nominal, Set Values( {"KATIE", "ALFRED", "HENRY", "MIKE"} ) ),
New Column( "height", Continuous, Set Values( [999, 999, 999, 111] ) ),
New Column( "weight", Continuous, Set Values( [999, 999, 999, 111] ) ),
New Column( "RANK", Continuous, Set Values( [3, 1, 2, 9] ) ),
New Column( "CODE", Continuous, Set Values( [0, 1, 1, 8] ) )
);
dt3 = dt1 << Join(
With( dt2),
Merge Same Name Columns,
By Matching Columns( :name = :name ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 1 ),
Preserve main table order( 1 )
);
name = dt1 << get name;
close(dt1, nosave );
dt3 << set name(name);
dt1 = dt3;Re: Aggiornamento tabella con get righeEcco un modo che potrebbe funzionare per te supponendo che il nome agisca come identificatore univoco:
Names Default To Here( 1 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = New Table( "Little Class",
Add Rows( 3 ),
New Column( "name", Character, Nominal, Set Values( {"KATIE", "ALFRED", "HENRY", "MIKE"} ) ),
New Column( "height", Continuous, Set Values( [999, 999, 999, 111] ) ),
New Column( "weight", Continuous, Set Values( [999, 999, 999, 111] ) ),
New Column( "RANK", Continuous, Set Values( [3, 1, 2, 9] ) ),
New Column( "CODE", Continuous, Set Values( [0, 1, 1, 8] ) )
);
dt1 << Update(
With( Data Table( "Little Class" ) ),
Match Columns( :name = :name ),
Add columns from Update table( {:RANK} ),
Replace columns in Main Table( {:height} )
);
//Get names as associative arrays
names1 = Associative Array(dt1:name << Get values);
names2 = Associative Array(dt2:name << Get Values);
//Get the intersection (replaces names1)
names1 << Intersect(names2);
//Get intersection names as List
intersection = names1 << Get Keys;
//Find rows
update_rows = dt2 << Get Rows Where(contains(intersection, :name)>0);