Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embeddings #65

Merged
merged 19 commits into from
Jul 14, 2021
Merged

Embeddings #65

merged 19 commits into from
Jul 14, 2021

Conversation

woksin
Copy link
Contributor

@woksin woksin commented Jun 28, 2021

Summary

Adds a new feature, Embeddings! They are similar to Projections, but they are meant to be used to event source changes coming from an external system. Check the sample for an example.

Added

  • Embeddings! You can use them inline with the WithEmbeddings() builder, or by specifying the ResolveUpdateToEvents, ResolveDeletionToEvents and On methods or attributes for a class. The embeddings can be updated, deleted and fetched from the client.Embeddings property.

@woksin woksin marked this pull request as draft June 28, 2021 20:48
var response = await _caller.Call(_getOneMethod, request, cancellation).ConfigureAwait(false);
response.Failure.ThrowIfFailureIsSet();

if (!_toSDK.TryConvert<TEmbedding>(response.State, out var state, out var error))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 5 locations. Consider refactoring.

onSignature) as IOnMethod<TEmbedding>;
}

Type GetOnMethodSignature(MethodInfo method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

=> eventTypes.GetFor(typeof(TEvent));

/// <inheritdoc/>
public Task<Try<ProjectionResult<TReadModel>>> TryOn(TReadModel readModel, object @event, EmbeddingProjectContext context)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

throw new InvalidProjectionMethodReturnType(method.ReturnType);
}

Type GetTypedOnMethodSignature(MethodInfo method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

readonly Type _embeddingType = typeof(TEmbedding);

/// <inheritdoc/>
public void BuildAndRegister(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method BuildAndRegister has 57 lines of code (exceeds 25 allowed). Consider refactoring.

@joelhoisko joelhoisko marked this pull request as ready for review July 5, 2021 13:48
@joelhoisko joelhoisko changed the title Embeddings pre-release branch Embeddings Jul 6, 2021
return true;
}

bool TryAddConventionRemoveMethod(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return okay;
}

IRemoveMethod<TEmbedding> CreateRemoveMethod(MethodInfo method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return okay;
}

ICompareMethod<TEmbedding> CreateCompareMethod(MethodInfo method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

cancellation);
}

bool TryAddOnMethods(IEventTypes eventTypes, IDictionary<EventType, IOnMethod<TReadModel>> eventTypesToMethods, ILogger logger)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

.ForCompare(embeddingId, eventTypes, loggerFactory)
.TryBuild(out var compareMethod))
{
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

return true;
}

bool TryAddConventionUpdateMethod(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return okay;
}

IUpdateMethod<TEmbedding> CreateUpdateMethod(MethodInfo method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return okay;
}

IDeleteMethod<TEmbedding> CreateDeleteMethod(MethodInfo method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return true;
}

bool TryAddDecoratedUpdateMethod(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

.ForDelete(embeddingId, eventTypes, loggerFactory)
.TryBuild(out var deleteMethod))
{
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

return true;
}

bool TryAddDecoratedDeleteMethod(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

/// </summary>
/// <param name="method">The out of the method.</param>
/// <returns>A bool indicating whether the build succeeded.</returns>
public bool TryBuild(out IUpdateMethod<TEmbedding> method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

/// </summary>
/// <param name="method">The out of the method.</param>
/// <returns>A bool indicating whether the build succeeded.</returns>
public bool TryBuild(out IDeleteMethod<TEmbedding> method)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

}

/// <inheritdoc/>
public async Task<ProjectionResult<TReadModel>> On(TReadModel readModel, object @event, EventType eventType, EmbeddingProjectContext context, CancellationToken cancellation)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

@joelhoisko joelhoisko merged commit 32b7cef into master Jul 14, 2021
@joelhoisko joelhoisko deleted the 9.1.0-embeddings branch July 14, 2021 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants