⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 distributerecord.pm

📁 普通的ETL工具
💻 PM
字号:
# vim:ts=4 sw=4
# ----------------------------------------------------------------------------------------------------
#  Name		: ETL::Pequel3::Type::Section::DistributeRecord.pm
#  Created	: 22 June 2006
#  Author	: Mario Gaffiero (gaffie)
#
# Copyright 1999-2007 Mario Gaffiero.
# 
# This file is part of Pequel(TM).
# 
# Pequel is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# Pequel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Pequel; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# ----------------------------------------------------------------------------------------------------
# Modification History
# When          Version     Who     What
# ----------------------------------------------------------------------------------------------------
package ETL::Pequel3::Type::Section::DistributeRecord;
require 5.005_62;
use strict;
use warnings;
use ETL::Pequel3::Type::Section;
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::DistributeRecord::Abstract;
	use base qw(ETL::Pequel3::Type::Section::Abstract);
	use Class::STL::ClassMembers
		qw( 
			dataset_spec
			output_dataset
			condition_exp
			condition_exp_raw
		),
		Class::STL::ClassMembers::DataMember->new(name => 'target_mem_name', default => 'dataset_spec'),
		Class::STL::ClassMembers::DataMember->new(name => 'item_type', default => 'ETL::Pequel3::Type::Section::Item::CondExp'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}");
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->attributes()->push_back(
			ETL::Pequel3::Type::Properties::DataSetSpec->new(),
		);
	}
	sub prepare
	{
		my $self = shift;
		$self->condition_exp(
			$self->items()->size()
				? join(' || ', map($_->condition_exp(), $self->items()->to_array()))
				: undef
		);
		$self->output_dataset($self->pequel_ref()->factories()->output_datasets()->factory( 
			dataset_spec => $self->dataset_spec(), 
			pequel_ref => $self->pequel_ref()
		));
		$self->err()->trace_msg(10, "@{[ $self->pequel_ref()->pequel_name() ]} -->"
			. $self->section_name() . ':' . $self->dataset_spec()
			. "; Dataset->fdname:" . $self->output_dataset()->datasource()->fdname()
		);
	}
	sub select
	{
		my $self = shift;
		my %p = @_;
		$self->err()->user_error(10211, "Section '@{[ 
			$self->section_name() ]}' select() function requires '@{[ $self->target_mem_name() ]}' parameter!")
			unless (exists($p{$self->target_mem_name()}));
		my $s;
		return $s if (($s = $self->exists($p{$self->target_mem_name()})) != 0);
		$self->add(%p);
		$self->back()->attributes()->set(@_);
		return $self->back();
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::CopyRecord;
	use base qw(ETL::Pequel3::Type::Section::DistributeRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'copy_record'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => 'This section is used to specify a record distribution action. Please refer to the specific F<copy_record_on_input> and F<copy_record_on_output> section type descriptions for detailed information.');
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->attributes()->push_back(
			ETL::Pequel3::Type::Properties::On->new(),
		);
		return $self;
	}
	sub select
	{
		my $self = shift;
		my %p = @_;
		$self->err()->user_error(10211, "Section '@{[ 
			$self->section_name() ]}' select() function requires 'on' parameter!")
			unless (exists($p{on}));
		return $self->pequel_ref()->section("@{[ $self->section_name() ]}_on_@{[ lc($p{on}) ]}")->select(@_);
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::CopyRecordOnInput;
	use base qw(ETL::Pequel3::Type::Section::DistributeRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'copy_record_on_input'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record distribution action. The input record will be copied to the distribution specified in the I<dataset_spec> property. The optional F<condition_exp> item attribute will determine if the record is copied; if the record evaluates to true on the condition then the record is copied. If no F<condition_exp> has been specified then all incoming records will be copied.\n\n\nThe F<copy_record_on_input> action will take place right after the F<divert_record_on_input> and before the I<grouping break control>.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.");
	use Class::STL::ClassMembers::Constructor;
	sub prepare
	{
		my $self = shift;
		$self->SUPER::prepare(@_);
		$self->output_dataset()->map_output(main => $self->pequel_ref(), on => 'input');
	}
	sub parse
	{
		my $self = shift;
		$self->condition_exp_raw($self->pequel_ref()->parser_input()->used_by($self)
			->translate($self->condition_exp())->raw())
			if (defined($self->condition_exp()));
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::CopyRecordOnOutput;
	use base qw(ETL::Pequel3::Type::Section::DistributeRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'copy_record_on_output'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record distribution action. The output (aggregated) record will be copied to the distribution specified in the I<dataset_spec> property. The optional F<condition_exp> item attribute will determine if the record is copied; if the record evaluates to true on the condition then the record is copied. If no F<condition_exp> has been specified then all outgoing records will be copied.\n\n\nThe F<copy_record_on_output> action will take place right after the F<divert_record_on_output> and before the I<print output> statements.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.");
	use Class::STL::ClassMembers::Constructor;
	sub prepare
	{
		my $self = shift;
		$self->SUPER::prepare(@_);
		$self->output_dataset()->map_output(main => $self->pequel_ref(), on => 'output');
	}
	sub parse
	{
		my $self = shift;
		$self->condition_exp_raw($self->pequel_ref()->parser_output()->used_by($self)
			->translate($self->condition_exp())->raw())
			if (defined($self->condition_exp()));
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::DivertRecord;
	use base qw(ETL::Pequel3::Type::Section::DistributeRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'divert_record'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => 'This section is used to specify a record distribution action. Please refer to the specific F<divert_record_on_input> and F<divert_record_on_output> section type descriptions for detailed information.');
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->attributes()->push_back(
			ETL::Pequel3::Type::Properties::On->new(),
		);
		return $self;
	}
	sub select
	{
		my $self = shift;
		my %p = @_;
		$self->err()->user_error(10211, "Section '@{[ 
			$self->section_name() ]}' select() function requires 'on' parameter!")
			unless (exists($p{on}));
		return $self->pequel_ref()->section("@{[ $self->section_name() ]}_on_@{[ lc($p{on}) ]}")->select(@_);
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::DivertRecordOnInput;
	use base qw(ETL::Pequel3::Type::Section::DistributeRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'divert_record_on_input'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record distribution action. The input record will be I<diverted> to the distribution specified in the I<dataset_spec> property. The F<condition_exp> item attribute will determine if the record is diverted; if the record evaluates to true on the condition then the record is diverted. The diverted records will not appear in the input processing.\n\n\nThe F<divert_record_on_input> action will take place right after the F<reject_record_on_input> and before the F<copy_record_on_input> actions.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.");
	use Class::STL::ClassMembers::Constructor;
	sub prepare
	{
		my $self = shift;
		$self->err()->user_error(10250, "Section @{[ 
			$self->section_name() ]}) requires one or more item condition statements!")
			unless ($self->items()->size());
		$self->SUPER::prepare(@_);
		$self->output_dataset()->map_output(main => $self->pequel_ref(), on => 'input');
	}
	sub parse
	{
		my $self = shift;
		$self->condition_exp_raw($self->pequel_ref()->parser_input()->used_by($self)
			->translate($self->condition_exp())->raw())
			if (defined($self->condition_exp()));
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::DivertRecordOnOutput;
	use base qw(ETL::Pequel3::Type::Section::DistributeRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'divert_record_on_output'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record distribution action. The output (aggregated) record will be I<diverted> to the distribution specified in the I<dataset_spec> property. The F<condition_exp> item attribute will determine if the record is diverted; if the record evaluates to true on the condition then the record is diverted. The diverted records will not appear in the output.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.\n\n\nThe F<divert_record_on_output> action will take place right after the F<reject_record_on_output> and before the F<copy_record_on_output> actions.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.");
	use Class::STL::ClassMembers::Constructor;
	sub prepare
	{
		my $self = shift;
		$self->err()->user_error(10250, "Section @{[ 
			$self->section_name() ]}) requires one or more item condition statements!")
			unless ($self->items()->size());
		$self->SUPER::prepare(@_);
		$self->output_dataset()->map_output(main => $self->pequel_ref(), on => 'output');
	}
	sub parse
	{
		my $self = shift;
		$self->condition_exp_raw($self->pequel_ref()->parser_output()->used_by($self)
			->translate($self->condition_exp())->raw())
			if (defined($self->condition_exp()));
	}
}
# ----------------------------------------------------------------------------------------------------
1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -