def ii_init(self, record_info_in: sdk.RecordInfo) -> bool: if not self.parent.params_are_valid(): return False self.IncomingRecordInfo = record_info_in self.FileNameField = record_info_in.get_field_by_name(self.parent.FileNameFieldName) self.NameField = record_info_in.get_field_by_name(self.parent.NameFieldName) return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: # Make sure the user provided a field to parse if self.parent.SourceFieldName is None: self.parent.display_error_msg('Select a source field') return False # Make sure the user provided a field to parse if self.parent.DestFieldName is None: self.parent.display_error_msg('Select a destination field') return False # Get information about the source path field self.SourceField = record_info_in.get_field_by_name( self.parent.SourceFieldName) #match_field_type: Sdk.FieldType = self.SourceField.type #match_field_size: int = self.SourceField.size # Get information about the destination path field self.DestField = record_info_in.get_field_by_name( self.parent.DestFieldName) # Returns a new, empty RecordCreator object that is identical to record_info_in. record_info_out = record_info_in.clone() # Adds field to record with specified name and output type. self.OutputField = record_info_out.add_field(self.output_name, self.output_type, self.output_size) # Lets the downstream tools know what the outgoing record metadata will look like self.parent.output.init(record_info_out) self.parent.error_output.init(record_info_out) # Creating a new, empty record creator based on record_info_out's record layout. self.record_creator = record_info_out.construct_record_creator() # Instantiate a new instance of the RecordCopier class. self.record_copier = Sdk.RecordCopier(record_info_out, record_info_in) # Map each column of the input to where we want in the output. for index in range(record_info_in.num_fields): # Adding a field index mapping. self.record_copier.add(index, index) # Let record copier know that all field mappings have been added. self.record_copier.done_adding() return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: self.EventField = record_info_in.get_field_by_name('Event', throw_error=False) if self.EventField is None: self.parent.display_error_msg("Incoming data source must contain an 'Event' text field that pushes 'Start' and 'End' events") return False self.parent.Output.init(self.Info) return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: self.uploadFileField = record_info_in.get_field_by_name( self.parent.uploadFileField) self.output_info = self._generate_output_record_info() self.output_creator = self.output_info.construct_record_creator() self.batch_read_url = self.parent.endpoint + """vision/v2.0/read/core/asyncBatchAnalyze""" self.parent.output.init(self.output_info) return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: # Make sure the user provided a field to parse if self.parent.url is None: self.parent.display_error_msg('Select a source field') return False # Get information about the source path field try: self.SourceField = record_info_in.get_field_by_name( self.parent.url) except Exception as e: self.parent.display_error_msg( f'Invalid source field: {self.parent.url}') return False #match_field_type: Sdk.FieldType = self.SourceField.type #match_field_size: int = self.SourceField.size # Returns a new, empty RecordCreator object that is identical to record_info_in. self.record_info_out = record_info_in.clone() #output field config self.fields = [['protocol', Sdk.FieldType.string, 20], ['net_location', Sdk.FieldType.string, 100], ['path', Sdk.FieldType.string, 1000], ['query', Sdk.FieldType.string, 1000], ['parsed_query', Sdk.FieldType.string, 1000], ['fragment', Sdk.FieldType.string, 100], ['hostname', Sdk.FieldType.string, 100], ['port', Sdk.FieldType.int32, 10]] self.outRecords = [] # Adds field to record with specified name and output type. for name, dtype, size in self.fields: self.outRecords.append( self.record_info_out.add_field(name, dtype, size)) # Lets the downstream tools know what the outgoing record metadata will look like self.parent.output.init(self.record_info_out) # Creating a new, empty record creator based on record_info_out's record layout. self.record_creator = self.record_info_out.construct_record_creator() # Instantiate a new instance of the RecordCopier class. self.record_copier = Sdk.RecordCopier(self.record_info_out, record_info_in) # Map each column of the input to where we want in the output. for index in range(record_info_in.num_fields): # Adding a field index mapping. self.record_copier.add(index, index) # Let record copier know that all field mappings have been added. self.record_copier.done_adding() return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: self.EventField = record_info_in.get_field_by_name('Event', throw_error=False) if self.EventField is None: self.parent.display_error_msg("Incoming data source must contain an 'Event' text field that pushes 'Start' and 'End' events") return False self.parent.Output.init(self.RecordInfo) checkpoint_store = BlobCheckpointStore.from_connection_string(self.parent.CheckpointConnStr, self.parent.CheckpointContainer) self.Client = EventHubConsumerClient.from_connection_string(self.parent.EventHubsConnStr, consumer_group=self.parent.ConsumerGroup, eventhub_name=self.parent.EventHubName, checkpoint_store=checkpoint_store) self.parent.display_info_msg("Event Hubs receive client created") return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: # Make sure the user provided a field to parse if self.parent.CompanyNamesField is None: self.parent.display_error_msg('Select a field') return False self.CompanyNamesField = record_info_in.get_field_by_name( self.parent.CompanyNamesField) # Returns a new, empty RecordCreator object that is identical to record_info_in. output_record = record_info_in.clone() # Adds field to record with specified name and output type. self.IdField = output_record.add_field("Glassdoor ID", Sdk.FieldType.v_wstring, 100) self.NameField = output_record.add_field("Glassdoor Name", Sdk.FieldType.v_wstring, 100) self.ReviewLinkField = output_record.add_field( "Begin Review Search Link", Sdk.FieldType.v_wstring, 1000) self.ReviewPagesField = output_record.add_field( "Review Pages", Sdk.FieldType.int64) self.InterviewLinkField = output_record.add_field( "Begin Interview Search Link", Sdk.FieldType.v_wstring, 1000) self.InterviewPagesField = output_record.add_field( "Interview Pages", Sdk.FieldType.int64) # Lets the downstream tools know what the outgoing record metadata will look like self.parent.Output.init(output_record) self.parent.Reviews.init(self.ReviewsRecord) self.parent.Interviews.init(self.InterviewsRecord) # Creating a new, empty record creator based on record_info_out's record layout. self.OutputCreator = output_record.construct_record_creator() # Instantiate a new instance of the RecordCopier class. self.OutputCopier = Sdk.RecordCopier(output_record, record_info_in) # Map each column of the input to where we want in the output. for index in range(record_info_in.num_fields): # Adding a field index mapping. self.OutputCopier.add(index, index) # Let record copier know that all field mappings have been added. self.OutputCopier.done_adding() return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: self.InInfo = record_info_in self.Text1Field = record_info_in.get_field_by_name(self.parent.Text1) self.Text2Field = record_info_in.get_field_by_name(self.parent.Text2) self.OutInfo = self.InInfo.clone() self.ScoreField = self.OutInfo.add_field(self.parent.OutputField, Sdk.FieldType.double, source=self.parent.label) self.Creator = self.OutInfo.construct_record_creator() self.Copier = Sdk.RecordCopier(self.OutInfo, self.InInfo) index = 0 while index < self.InInfo.num_fields: self.Copier.add(index, index) index += 1 self.Copier.done_adding() self.parent.Output.init(self.OutInfo) return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: self.EventField = record_info_in.get_field_by_name('Event', throw_error=False) if self.EventField is None: self.parent.display_error_msg( "Incoming data source must contain an 'Event' text field that pushes 'Start' and 'End' events" ) return False self.parent.Output.init(self.RecordInfo) self.Loop = asyncio.get_event_loop() self.Connection = pika.BlockingConnection( pika.ConnectionParameters(host=self.parent.Host)) self.Channel = self.Connection.channel() self.Channel.queue_declare(self.parent.Queue) self.Channel.basic_consume(queue=self.parent.Queue, on_message_callback=self._push_event, auto_ack=True) self.parent.display_info_msg("RabbitMQ connection created") return True
def ii_init(self, record_info_in: Sdk.RecordInfo) -> bool: # Get the fields from the incoming connection fields: List[str] = [] for field in record_info_in: fields.append(field.name) # Map each column of the input to where we want in the output. record_info_out = Sdk.RecordInfo(self.parent.alteryx_engine) self.record_copier = Sdk.RecordCopier(record_info_out, record_info_in) translations = sort_fields(fields, self.parent.SortList, self.parent.Alphabetical) for translation in translations: Sdk.Field = record_info_out.add_field(record_info_in.get_field_by_name(translation.name)) self.record_copier.add(translation.index_to, translation.index_from) self.record_copier.done_adding() # Lets the downstream tools know what the outgoing record metadata will look like self.parent.output.init(record_info_out) # Creating a new, empty record creator based on record_info_out's record layout. self.record_creator = record_info_out.construct_record_creator() return True
def build_ayx_record_from_list( values_list: List[Any], metadata_list: List[dict], record_info: sdk.RecordInfo, record_creator: Optional[sdk.RecordCreator] = None, ) -> Tuple[object, object]: """ Build a record from a list of values. Takes a list of values that represents a single row of data, along with metadata and a blank or already populated Alteryx RecordInfo object, and returns a tuple containing a populated Alteryx RecordRef object and an already initialized RecordCreator object. The returned RecordCreator object can optionally be passed back into the function, allowing for improved performance when looping through a list of new values. Parameters ---------- values_list : List[Any] A list of Python objects of any type that represents a single record of data. The 0th index of the list represents data in the first column of the record, and so on. metadata_list : List[dict] (This might not be a list) A list of the names, types, sizes, sources, and descriptions for each respective column. These are used to generate the Alteryx RecordInfo object (if it doesn't already exist) for the names of each respective Field object. record_info : object An Alteryx RecordInfo object. Alteryx RecordInfo objects act as containers for the necessary metadata needed by the Alteryx engine to generate, identify, and manipulate each record of data passing through the tool. record_creator : Optional[object] An optional Alteryx RecordCreator object. The RecordCreator object is created by calling the construct_record_creator method on an Alteryx RecordInfo object. It is a stateful object which is populated with values as a side-effect of this function. When its finalize method is called, it returns an actual reference to the record's data, in the form of an Alteryx RecordRef object. If no record_creator object is passed into the function, one will be created using the record_info object. The function will automatically reset the record_creator if one is passed in. Returns ------- Tuple(object, object) First value in tuple: Alteryx RecordRef object, with each Field populated with the respective values in the values_list parameter. Second value in tuple: Alteryx RecordCreator object. If one was passed in as a parameter, it returns it after creating a record with it. If one is not passed in, it creates a new one from the RecordInfo param, uses it to create a record, and returns it. """ columns = [ Column( metadata_list[i].name, metadata_list[i].type, metadata_list[i].size, metadata_list[i].source, metadata_list[i].description, values_list[i], ) for i in range(len(metadata_list)) ] if record_info.num_fields == 0: for column in columns: add_output_column_to_record_info(column, record_info) if record_creator: record_creator.reset() else: record_creator = record_info.construct_record_creator() for column in columns: field = record_info.get_field_by_name(column.name) set_field_value(field, column.value, record_creator) ayx_record = record_creator.finalize_record() return (ayx_record, record_creator)