tomasfabian / ksqlDB.RestApi.Client-DotNet

ksqlDb.RestApi.Client is a C# LINQ-enabled client API for issuing and consuming ksqlDB push and pull queries and executing statements.
MIT License
94 stars 25 forks source link

SourceExtensions inaccessible #28

Closed KovtunV closed 2 years ago

KovtunV commented 2 years ago

Hello, why ksqlDB.RestApi.Client.KSql.Linq.SourceExtensions is internal?

I want to join stream to stream, but get en error Stream-Stream joins must have a WITHIN clause specified. None was provided

However can't reach Within extension method since it's internal.

tomasfabian commented 2 years ago

Hi @KovtunV, you are right SourceExtensions shouldn't be internal. The fix will be next in an upcoming release. You can verify it with the release candidate 2.2.0-rc.1 I've just published.

Thank you very much for reporting this issue!

Regards Tomas.

KovtunV commented 2 years ago

@tomasfabian Thank you, now it's opened but generates wrong query.

 var stream = context
            .CreateQueryStream<EnduserModel>("endusers")
            .WithOffsetResetPolicy(AutoOffsetReset.Latest)
            .Join(Source.Of<SubEnduserModel>("sub_endusers").Within(Duration.OfDays(1)),
            enduser => K.Functions.ExtractJsonField(enduser.Data, "$.enduser_id"),
            sub => sub.EnduserId,
            (enduser, sub) => new {  EnduserId = sub.EnduserId, Name = sub.Name, Raw = enduser.Data });
SELECT sub.EnduserId EnduserId, sub.Name Name, enduser.Data AS Raw FROM endusers enduser
INNER JOIN sub_endusers sub
WITHIN 1 DAYS ON enduser.EXTRACTJSONFIELD(enduser.Data, '$.enduser_id') = sub.EnduserId
EMIT CHANGES;

wrong text: function enduser.EXTRACTJSONFIELD

Byt the way, is it possible to create stream as select via LINQ? Like

CREATE STREAM EVENTS as
    SELECT sub.EnduserId EnduserId, sub.Name Name, enduser.Data Raw
    FROM endusers enduser
        INNER JOIN sub_endusers sub
        WITHIN 1 DAYS GRACE PERIOD 1 DAYS
        ON EXTRACTJSONFIELD (enduser.Data, '$.enduser_id') = sub.EnduserId;
tomasfabian commented 2 years ago

@KovtunV you found an edge case with ksql functions in joins which I haven't realized up to this time. I fixed it. I released ksqlDB.RestApi.Client 2.2.0, please verify it again. Thanks a lot!

Regarding the create streams as select check the ToStatementString method or CreateOrReplaceTableStatement.

KovtunV commented 2 years ago

@tomasfabian It works, thanks!