Scope Instruction - Processor

本文详细介绍了PROCESS语句的使用方法,包括如何将一个RowSet转换为另一个RowSet,实现数据的转换、增删列、过滤及扩展等操作。文中通过两个实例展示了如何应用WHERE和HAVING子句来分别过滤输入和输出数据。

PROCESS

 

The PROCESS statement is used to convert one RowSet to another RowSet.  Uses include:

  • Transformations
  • Adding/Removing columns
  • Filtering data
  • Expanding data

Syntax

All PROCESS statements require:

  • PROCESS [input]
  • PRODUCE column(s)
  • USING processor

Additionally, users can supply a WHERE or HAVING statement to either filter the input or output.

Example (1)

This is taken from the Processor page.

PROCESS

PRODUCE A,B,C,D

USING MyProcessor(-a);

What this is saying is:

  1. Input the RowSet produced by the previous command
  2. Output the columns      "A", "B", "C", and "D" with types      determined by MyProcessor
  3. Use the Processor called      "MyProcessor" with the argument "-a" passed in

Example (2)

This example shows how to use WHERE and HAVING to filter the input and output Row objects.

PROCESS

PRODUCE A,B,C,D

USING MyProcessor(-a)

WHERE A != "scope"   //filter the output

HAVING A != "filter";   //filter the input

What this is saying is:

  1. Input the RowSet produced by the previous command
  2. Filter the input so that only rows having A not equal to      "filter" will be input
  3. Output the columns      "A", "B", "C", and "D" with types      determined by MyProcessor
  4. Use the Processor called      "MyProcessor" with the argument "-a" passed in
  5. Filter the output so that only rows having A not equal to      "scope" will be output

Processors

 

Processors are used to take a RowSet and produce a RowSet.  Typically, they are used for:

  • Transformations (i.e.      converting "A" to "Apple")
  • Adding/removing columns
  • Filtering (i.e removing Row objects where the first      column doesn't start with "A")

Internally, the WHERE and HAVING statements are implemented as Processors as well as many SELECT transformations.

Syntax

 

Let's look at the following script:

PROCESS

PRODUCE A,B,C,D

USING MyProcessor(-a)

WHERE A != "scope"

HAVING A != "filter";

What this is saying is:

  1. Input the RowSet produced by the previous command
  2. Filter the input so that only      rows having A not equal to "filter" will be further processed
  3. Output the columns      "A", "B", "C", and "D"
  4. Use the Processor called      "MyProcessor" with the argument "-a" passed in
  5. Filter the output so that      only rows having A not equal to "scope" will be output

Note: The WHERE and HAVING clauses are optional, but the other clauses are required. 

Writing a Processor

 

Syntax

 

The easiest thing to do is to right-click in the editor and select Implement-Processor.  Here's an example of a Processor that will filter data:

#CS

public class SampleProcessor : Processor

{

         public override Schema Produces(string[] requestedColumns, string[] args, Schema inputSchema)

         {

               return inputSchema.Clone();

         }

  

         public override IEnumerable<Row> Process(RowSet input, Row outputRow, string[] args)

         {

               foreach(Row row in input.Rows)

               {

                      //  Filter rows

                      if (!row[0].String.StartsWith("A"))

                     {

                            row.Copy(outputRow);

                            yield return outputRow;

                     }

                     

               }

         }

}

#ENDCS

The two methods that need to be implemented are:

  1. Produces
  2. Process

Tips

  • The outputRow object is      already handed to the Processor.
  • Do not create your own Row      object
  • Make your code efficient

转载于:https://www.cnblogs.com/yuqiyang/p/4536148.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值