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

Complex Types #4

Closed
HaroonSaid opened this issue Aug 25, 2021 · 6 comments
Closed

Complex Types #4

HaroonSaid opened this issue Aug 25, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@HaroonSaid
Copy link

HaroonSaid commented Aug 25, 2021

Hi Tomas

Is there a way to create a table, using a model that has arrays, my Kafka topic looks like
The approach that I took, was to create a CREATE TYPE and CREATE TABLE using the cli.
However, it would be nice if I can do it thru the c# client

    public abstract class AbstractProducerClass
    {
        public string Id { get; set; }
        public string Key { get; set; }
    }
    public class EventCategory
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
    // The Topic that needs the table
    public class ElasticSearchEvent : AbstractProducerClass
    {
        public string Title { get; set; }
        public string Description { get; set; }
        public long EventId { get; set; }
        public IEnumerable<EventCategory> EventCategories { get; set; }
    }
}

Thanks

@HaroonSaid
Copy link
Author

Thanks for the guidance.

@tomasfabian
Copy link
Owner

Hi @HaroonSaid,
C# version of Create type is not supported (implemented) in the current version.

Did you want to do something similar?

await restApiClient.CreateTableAsync<ElasticSearchEvent>(metadata);

Could you also provide the KSQL you used in the CLI mentioned above?

see also supported data types in selects

In selects try to use C# arrays instead of IEnumerable<T>

@HaroonSaid
Copy link
Author

A KSQL fragment create fragment

CREATE TYPE EventCategories AS STRUCT<id INTEGER, name VARCHAR, description VARCHAR>;

    CREATE TABLE IF NOT EXISTS "enrichedevents" ( 
        key VARCHAR PRIMARY KEY,
        id VARCHAR,
        ...
        eventCategories ARRAY<EventCategories>)
    WITH (KAFKA_TOPIC='enrichedevents', PARTITIONS=1, VALUE_FORMAT='JSON');

@tomasfabian tomasfabian added the enhancement New feature or request label Aug 26, 2021
@tomasfabian tomasfabian self-assigned this Aug 26, 2021
@tomasfabian
Copy link
Owner

I will try to prioritize this requirement, at the moment you can execute any arbitrary string statements from C# in the following manner:

using Kafka.DotNet.ksqlDB.KSql.RestApi;
using Kafka.DotNet.ksqlDB.KSql.RestApi.Statements;

internal async Task ExecuteStatementAsync()
{
  var ksqlDbUrl = @"http:\\localhost:8088";

  var httpClientFactory = new HttpClientFactory(new Uri(ksqlDbUrl));

  IKSqlDbRestApiClient restApiClient = new KSqlDbRestApiClient(httpClientFactory);

  var statement = @"CREATE TYPE EventCategories AS STRUCT<id INTEGER, name VARCHAR, description VARCHAR>;";

  KSqlDbStatement ksqlDbStatement = new(statement);

  var httpResponseMessage = await restApiClient.ExecuteStatementAsync(ksqlDbStatement);
}

@tomasfabian
Copy link
Owner

hi @HaroonSaid,
could you please try out the above requested feature?

CreateTypeAsync

Install-Package Kafka.DotNet.ksqlDB -Version 1.6.0-rc.1
var  httpResponseMessage = await restApiClient.CreateTypeAsync<EventCategory>();

@tomasfabian
Copy link
Owner

I released v1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants