GitHub user chenlica closed a discussion: How to integrate a new operator into 
Texera (from old wiki)

>From the page 
>https://github.com/apache/texera/wiki/How-to-integrate-a-new-operator-into-Texera
> (may be dangling)

====
Here we only talk about operator that does operation on retrieved data from 
source operator(e.g. sentiment analytics). This tutorial will not be suitable 
for source operator and result operator.
## What to do on backend
### Construct a predicate class

1. This class will be used to generate your operator object. It should extend 
from predicateBase. You need to add your predicate class to predicateBase file 
first.
2. The constructor of this predicate class should take all attributes you want 
your operator to take from the webpage(e.g. 
inputAttributeName/resultAttributeName), and store them. 
3. For each parameter of constructor, you'll want a method to return this 
argument for your operator class to use.
4. The predicate class should have a newOperator method, which constructs and 
returns a new operator object using this predicate object. E.g. `public 
dummyOperator newOperator() { return new dummyOperator(this); }`
5. Write a getOperatorMetadata method to specify group and description of your 
operator. Use `ImmutableMap.<~>builder` to do it.
### Construct a operator class
1. This class should extend from one of the classes from 
`api/src/main/java/edu/uci/ics/texera/api/dataflow`
2. This class should have a constructor which takes a predicate object and 
stores it.
3. This class should have a `setInputOperator` method, which specifies the 
previous operator(inputOperator).
4. This class should have a `open` method, which sets our inputSchema to be the 
inputOperator's ourputSchema and transforms our inputSchema into appropriate 
outputSchema. Then method `open` sets the cursor to `OPENED`.
5. This class should have a `getNextTuple` method, which calls `getNextTuple` 
of the inputOperator to get data from previous step; does operation on this 
data; adds generated field to the end if necessary; and returns the tuple.
6. This class should have a `close` method to set the cursor to `CLOSED`.
7. This class should have a `transformToOutputSchema` method, which takes 
inputSchema, modifies it, and returns the outputSchema.
### Generate JsonSchema
1. Open 
`dataflow/src/main/java/edu/uci/ics/texera/api/dataflow/common/JsonSchemaHelper.java`
2. Comment the first line in `main` function
3. Uncomment the second line in `main` function
4. Change the parameter to your predicate class
5. Run it, a schema should appear in the directory of your predicate class

It is a good idea to write a test function for your operator in 
`dataflow/src/main/java/edu/uci/ics/texera/api/dataflow/common/PredicateBaseTest.java`
## What to do on frontend
1. Add html element to `core/gui/app/operatorbar/operator-bar.component.html`, 
and set an unique id to it
2. Add relevant code to `core/gui/app/services/mock-data.ts`, remember to 
specify your operator's id at the bottom of the file
3. Add relevant code to 
`dataflow/src/main/java/edu/uci/ics/texera/dataflow/plangen/OperatorArityConstants.java`

## Check the result
Use [Running Texera 
GUI](https://github.com/Texera/texera/wiki/Running-Texera-GUI) to compile and 
run backend/frontend

GitHub link: https://github.com/apache/texera/discussions/3969

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]

Reply via email to