Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to achieve schema (columns and types) using @DiscoverSchema annotation

Hi All,

I am not able to get schema columns names for my input component as per module name using  @DiscoverSchema,Please help me with code. I have written code like below in service class .I need to write any thing in dataset class.

thanks,

venkat.

 @DiscoverSchema("guessSchema")
public Schema guessSchema(@Option("dataset") final VtigercrmComponentsDataSet dataset ,final RecordBuilderFactory factory)
{

final Schema.Entry.Builder entryBuilder = factory.newEntryBuilder();
final Schema.Builder schemaBuilder = factory.newSchemaBuilder(org.talend.sdk.component.api.record.Schema.Type.RECORD);


Schema.Type type = Schema.Type.STRING;
//return (Schema) schemaBuilder.withEntry(entryBuilder.withName("name").withType(type).withNullable(false).build());

return factory.newSchemaBuilder(Schema.Type.RECORD)
.withEntry(factory.newEntryBuilder().withName("ResponseContent").withType(Schema.Type.LONG).build()).build();
}     

Labels (2)
7 Replies
Anonymous
Not applicable
Author

Hi @Venkat_C ,

 

This guess schema will work only if your dataset is named "guessSchema", is it the case?

 

 

igorbeslic
Contributor III
Contributor III

Hi @Venkat_C did you get it working?

My team had same problem see thread:

https://community.talend.com/t5/Component-Development/Producer-and-DiscoverScheme/m-p/149874#M339

If you got it working what TS version you work with and which API version you use to develop your components?

 

Thank you!

Anonymous
Not applicable
Author

Hi @igorbeslic ,

 

Yah,its working perfectly '@DiscoverSchema,i have declare List instance  in my dataset class as like below and written @DiscoverSchema in service class.please find below link,it will use for create schema.

 

https://talend.github.io/component-runtime/main/1.1.3/record-types.html

 

@Option
@Structure(discoverSchema = "guessTableSchema",type=Type.IN)
@Documentation(value = "List of field names to return in the response.")
private List<String> fields = new ArrayList<>();

 

regards,

venkat

igorbeslic
Contributor III
Contributor III

Hi @Venkat_C thank you for your hints! Still for me documentation links are worthless. In link you provided there is no any note about:

@Option
@Structure(discoverSchema = "guessTableSchema",type=Type.IN)
@Documentation(value = "List of field names to return in the response.")
private List<String> fields = new ArrayList<>();

Do you have your component code available at GitHub? I sound desperate, but I think it would help more than all Telned documentation links people share in this forum. Or if you can share in this thread all important parts?


I used your hints with "@Structure" annotation but it does not trigger "@DiscoverSchema" method in "@Service" class. I put Talend Studio 7.2.1 M3 in debug mode and it does not track any interaction with service class. The "Discover schema" button in TS UI triggers "@Producer" method in my mapper's source class (invoked by "org.talend.sdk.component.runtime.di.schema.TaCoKitGuessSchema#guessSchemaThroughResult(java.lang.Object)").

 

Are you sure schema you get in your UI really comes from service annotated method "@DiscoverSchema"?

 

Thank you very much!

Anonymous
Not applicable
Author

Hi Igor

Please dont mix two API - both use the same action.

1. @Structure is to have completion on a configuration field,
2. Guess Schema button is to initialize the struct associated to the component. For inputs, it tries to match a discover schema action based on the dataset used in the input configuration, if none is found it runs the producer method to get data.

I suspect something is fishy in the second case for you - was your action name originally if I recall correctly. Did you fix it, redeployed the component and restarted the studio or used the reload feature?

If still an issue please share your current/updated code to let us check what is missing.
igorbeslic
Contributor III
Contributor III

Hi @rmannibucau my component project is here

https://github.com/igorbeslic/talend-poc

 

Service implementation:

https://github.com/igorbeslic/talend-poc/blob/master/src/main/java/com/liferay/ebus/service/EBusServ...

 

Once deployed Talend Studio never invokes:

@DiscoverSchema(value = "Dataset")
public Schema discoverSchema(
	@Option("dataset") Dataset dataset,
	final RecordBuilderFactory recordBuilderFactory) {
//...
}

 

Thank you very much!!!

 

UPDATE:

I debug GuessSchema:

public TaCoKitGuessSchema(final PrintStream out, final Map<String, String> configuration, final String plugin,
            final String family, final String componentName, final String action)

last argument, "action" passed to TaCoKitGuessSchema is null. What could be reason for it?

Safus
Creator
Creator

Hi,

someone is facing this problem with the @DiscoverSchema ?

The method in my service class is triggered and my schema is created but the button never respects the order and never returning the same order.

It's all-time random :

 

0693p00000BWrzlAAD.png0693p00000BWrzWAAT.pngAny Help ?

Thank you