Skip to content

Instantly share code, notes, and snippets.

View samueleresca's full-sized avatar

Samuele Resca samueleresca

View GitHub Profile
namespace deequ.Analyzers
{
interface IAnalyzer<out M>
{
M Calculate(DataFrame data, Option<IStateLoader> aggregateWith = default, Option<IStatePersister> saveStateWith = default);
IEnumerable<Action<StructType>> Preconditions();
M ToFailureMetric(Exception e);
void AggregateStateTo(IStateLoader sourceA, IStateLoader sourceB, IStatePersister target);
M LoadStateAndComputeMetric(IStateLoader source);
void CopyStateTo(IStateLoader source, IStatePersister target);
VerificationResult result;
//...
if (result.Status == CheckStatus.Success) {
Console.WriteLine("Success");
} else {
Console.WriteLine("Errors:");
IEnumerable<ConstraintResult> constraints = result
using System.Collections.Generic;
using deequ.Constraints;
namespace deequ.Checks
{
public class CheckResult
{
Check Check { get;}
CheckStatus Status { get;}
IEnumerable<ConstraintResult> ConstraintResults { get;}
public class VerificationResult
{
Dictionary<Check, CheckResult> CheckResults;
Dictionary<IAnalyzer<IMetric>, IMetric> Metrics;
CheckStatus Status;
}
val numTitles = fetchNumTitles();
val maxExpectedPhoneRatio = calcMaxExpectedPhoneRatio();
val result = VerificationSuite()
.onData(data)
.addCheck(Check(CheckLevel.Error, "Completeness + uniqueness on main fields")
.areComplete(Seq("customerId", "title", "impressionStart", "impressionEnd", "deviceType", "priority"))
.areUnique(Seq("customerId", "countryResidence", "deviceType", "title"))
.hasApproxCountDistinct("", value => numTitles >= value)
.hasHistogramValues("deviceType", distribution => maxExpectedPhoneRatio >= distribution("phone").ratio))
using deequ;
using deequ.Checks;
using deequ.Extensions;
using Microsoft.Spark.Sql;
namespace DeequExample
{
class Program
{
static void Main(string[] args)
1: Spawn 20 threads
2: Performing n.20 Set operations from multiple threads
Setting the following id: 16
Setting the following id: 3
Setting the following id: 18
Setting the following id: 1
Setting the following id: 0
Setting the following id: 2
Setting the following id: 6
Setting the following id: 7
using System.Threading;
using Xunit;
using Xunit.Abstractions;
namespace Blog.LRUCacheThreadSafe.Tests
{
public class LRUCacheSignalingTests
{
private const int threadNumbers = 20;
using System.Collections.Generic;
using System.Threading;
namespace Blog.LRUCacheThreadSafe
{
public class LRUCacheReaderWriterLock<T>
{
private readonly Dictionary<int, LRUCacheItem<T>> _records = new Dictionary<int, LRUCacheItem<T>>();
private readonly LinkedList<int> _freq = new LinkedList<int>();
private readonly ReaderWriterLockSlim _rw = new ReaderWriterLockSlim();
public class LRUCacheReaderWriterLock<T>
{
private readonly Dictionary<int, LRUCacheItem<T>> _records =new Dictionary<int, LRUCacheItem<T>>();
private readonly LinkedList<int> _freq = new LinkedList<int>();
private readonly ReaderWriterLockSlim _rw = new ReaderWriterLockSlim();
private readonly int _capacity;
public LRUCacheReaderWriterLock(int capacity)
{
_capacity = capacity;