logo
down
shadow

Compare 2 datasets (one to many rows)


Compare 2 datasets (one to many rows)

By : Rama Krishnan
Date : November 21 2020, 03:00 PM
I wish this helpful for you VB.NET Winforms , You can use DataView objects to "query" DataTables:
code :
Dim dtb As New DataTable
dtb.Columns.Add("Col0")
dtb.Columns.Add("Col1")
dtb.Columns.Add("Col2")
dtb.Columns.Add("Col3")
dtb.Rows.Add("R0C0", "R0C1", "A", "A")
dtb.Rows.Add("R1C0", "R1C1", "A", "A")
dtb.Rows.Add("R2C0", "R2C1", "A", "B")
dtb.Rows.Add("R3C0", "R3C1", "B", "B")

Dim dvw As New DataView(dtb)
dvw.RowFilter = "Col0>'R1C0'" 'WHERE 
dvw.Sort = "Col2 DESC" 'ORDER BY
For Each drv As DataRowView In dvw
  Dim drw As DataRow = drv.Row
  Console.WriteLine(drw("Col0") & " " & drw("Col1") & " " & drw("Col2") & " " & drw("Col3"))
Next
Dim dtbDistinct As DataTable = dtb.DefaultView.ToTable(True, {"Col2", "Col3"}) 'DISTINCT
For Each drw As DataRow In dtbDistinct.Rows
  Console.WriteLine(drw("Col2") & " " & drw("Col3"))
Next
Console.ReadKey()


Share : facebook icon twitter icon
Compare two datasets in C#

Compare two datasets in C#


By : Sazkiel
Date : March 29 2020, 07:55 AM
Does that help I think your error is compaing the Id string using ==. Try using Equals. I'd just use a foreach and select instead:
code :
foreach (DataRow row in ds.Tables[0].Rows)
{
    string filter = string.Format("Id = '{0}'", row["Id"]);
    DataRow[] rows = clientDS.Tables[0].Select(filter);
    if (rows.length == 0)
    {
        // insert here
    }
    else
    {
        // update here
    }
}
How to compare two datasets to check for missing rows which don't exist in the other dataset?

How to compare two datasets to check for missing rows which don't exist in the other dataset?


By : Mugambo
Date : March 29 2020, 07:55 AM
around this issue What is the datatype of Cnum, if it is int then default value is Zero.
You have to add else-if condition to check for example:
code :
else if (surveyCompareAssetsCheckData2.getCnum()== 0){

-------- logic here --------------------

}
else if (surveyCompareAssetsCheckData.getCnum() ==0){

----------logic here -----------

}
How to compare two datasets?

How to compare two datasets?


By : RWejlgaard
Date : March 29 2020, 07:55 AM
Hope that helps I am running a spark application that reads data from a few hive tables(IP addresses) and compares each element(IP address) in a dataset with all other elements(IP addresses) from the other datasets. The end result would be something like: , After the line:
code :
val dfBuffer = new it.unimi.dsi.fastutil.objects.ObjectArrayList[String](df.map(r => r(0).toString).collect())
df.map(r => r(0).toString).collect()
How to compare Datasets?

How to compare Datasets?


By : user2474874
Date : March 29 2020, 07:55 AM
hope this fix your issue So I did some experimenting and found out the following on Spark 2.4.0
code :
def equal(a: Dataset[Row], b: Dataset[Row], expected: Boolean) = {
  println(s"by logical hashCode ${a.queryExecution.logical.semanticHash == b.queryExecution.logical.semanticHash}")
  println(s"by logical sameResult ${a.queryExecution.logical.sameResult(b.queryExecution.logical)}")
  println(s"by optimized hashCode ${a.queryExecution.optimizedPlan.semanticHash == b.queryExecution.optimizedPlan.semanticHash}")
  println(s"by optimized sameResult ${a.queryExecution.optimizedPlan.sameResult(b.queryExecution.optimizedPlan)}")
  println(s"expected: $expected")
  println("\n")
}

val a = spark.createDataset(Seq(1, 2)).filter($"value" > 1).filter($"value" > 1).toDF
val b = spark.createDataset(Seq(1, 2)).filter($"value" > 1).toDF
val c = spark.createDataset(Seq(2, 3)).filter($"value" > 1).toDF
val d = spark.createDataset(Seq(2, 3)).filter($"value" < 1).toDF
val e = spark.read.parquet("/test_1")
val f = spark.read.parquet("/test_1")
val g = spark.read.parquet("/test_2")
val h = spark.read.parquet("/test_1").filter($"value" < 1)
val i = spark.read.parquet("/test_1").filter($"value" > 1)

equal(a, b, true)
// by logical hashCode false 
// by logical sameResult false 
// by optimized hashCode true 
// by optimized sameResult true 
// expected: true 

equal(b, c, false)
// by logical hashCode false 
// by logical sameResult false 
// by optimized hashCode false 
// by optimized sameResult false 
// expected: false 


equal(c, d, false)
// by logical hashCode true 
// by logical sameResult false 
// by optimized hashCode false 
// by optimized sameResult false 
// expected: false 


equal(e, f, true)
// by logical hashCode true 
// by logical sameResult true 
// by optimized hashCode true 
// by optimized sameResult true 
// expected: true 

equal(e, g, false)
// by logical hashCode false 
// by logical sameResult false 
// by optimized hashCode false 
// by optimized sameResult false 
// expected: false

equal(h, i, false)
// by logical hashCode true 
// by logical sameResult false
// by optimized hashCode true
// by optimized sameResult false
// expected: false
Compare two datasets to find the rows that are not present in one of the datset in r

Compare two datasets to find the rows that are not present in one of the datset in r


By : Juan
Date : September 26 2020, 07:00 AM
it fixes the issue You can use the dplyr package which has a anti_join function for precisely this task:
code :
library(dplyr)
anti_join(dataset1, dataset2, by = "Id")
 anti_join(dataset2, dataset1, by = "Id")
shadow
Privacy Policy - Terms - Contact Us © voile276.org