예제 #1
0
def test_raw_record_container_construction():
    record_info = RecordInfo(AlteryxEngine())
    record_info.add_field(field_name="a", field_type=FieldType.byte)
    record_info.add_field(field_name="b", field_type=FieldType.fixeddecimal)

    with pytest.raises(ValueError):
        RawRecordContainer(record_info, record_info)
def test_record_copier_proxy():
    engine = AlteryxEngine()

    input_record_info = RecordInfo(engine)
    output_record_info = RecordInfo(engine)

    field_props = [
        {
            "field_name": "a",
            "field_type": FieldType.int32
        },
        {
            "field_name": "b",
            "field_type": FieldType.v_wstring
        },
    ]

    for props in field_props:
        input_record_info.add_field(**props)
        output_record_info.add_field(**props)

    record_copier_proxy = RecordCopierProxy(input_record_info,
                                            output_record_info, {
                                                "a": "a",
                                                "b": "b"
                                            })

    record = RecordRef(input_record_info)
    record.data["a"] = 123
    record.data["b"] = "Hello world"

    record_copier = record_copier_proxy.copy(record)

    assert record == record_copier.finalize_record()
    assert record is not record_copier.finalize_record()
예제 #3
0
def test_generate_records_from_df():
    df = pd.DataFrame({"a": [1, 2, 3], "b": ["Hello", "from", "blackbird"]})

    record_info = RecordInfo(AlteryxEngine())
    record_info.add_field(field_name="a", field_type=FieldType.byte)
    record_info.add_field(field_name="b", field_type=FieldType.v_string)

    record_generator = generate_records_from_df(df, record_info)

    num_rows, _ = df.shape

    for row, record in enumerate(record_generator):
        for column in list(df):
            assert record.finalize_record().data[column] == df[column][row]
예제 #4
0
def test_mapped_raw_record_container():
    input_record_info = RecordInfo(AlteryxEngine())
    input_record_info.add_field(field_name="a", field_type=FieldType.byte)
    input_record_info.add_field(field_name="b",
                                field_type=FieldType.fixeddecimal)

    storage_record_info = RecordInfo(AlteryxEngine())
    storage_record_info.add_field(field_name="c",
                                  field_type=FieldType.fixeddecimal)
    storage_record_info.add_field(field_name="d", field_type=FieldType.byte)

    field_map = {"a": "d", "b": "c"}

    container = RawRecordContainer(input_record_info, storage_record_info,
                                   field_map)

    record1 = RecordRef(input_record_info)
    record1.data["a"] = 123
    record1.data["b"] = 666.666

    record2 = RecordRef(input_record_info)
    record2.data["a"] = 456
    record2.data["b"] = 999.999

    records = [record1, record2]

    for record in records:
        container.add_record(record)

    for input_record, saved_record in zip(records, container.records):
        assert input_record.data["a"] == saved_record.finalize_record(
        ).data["d"]
        assert input_record.data["b"] == saved_record.finalize_record(
        ).data["c"]
예제 #5
0
def record_collection():
    record_info = RecordInfo(AlteryxEngine())
    record_info.add_field("a", FieldType.float)
    record_info.add_field("b", FieldType.float)

    record1 = RecordRef(record_info)
    record1.data["a"] = 123
    record1.data["b"] = 666.666

    record2 = RecordRef(record_info)
    record2.data["a"] = 456
    record2.data["b"] = 999.999

    records = [record1, record2]

    return record_info, records
    def _list_to_recordinfo(self,
                            rec_info: Sdk.RecordInfo,
                            field_list: list,
                            source: str = "SFTP Downloader"):
        """Adds fields to RecordInfo according to list
        
        :param rec_info: RecordInfo object to which fields are to be added
        :type rec_info: Sdk.RecordInfo
        :param field_list: List of dict() containing field information
        :type field_list: list
        """

        # Iterate through list
        for field in field_list:
            rec_info.add_field(field['name'],
                               field['type'],
                               field['size'],
                               source=source,
                               description=field['description'])

        return
예제 #7
0
def test_simple_raw_record_container():
    record_info = RecordInfo(AlteryxEngine())
    record_info.add_field(field_name="a", field_type=FieldType.byte)
    record_info.add_field(field_name="b", field_type=FieldType.fixeddecimal)

    container = RawRecordContainer(record_info)

    record1 = RecordRef(record_info)
    record1.data["a"] = 123
    record1.data["b"] = 666.666

    record2 = RecordRef(record_info)
    record2.data["a"] = 456
    record2.data["b"] = 999.999

    records = [record1, record2]

    for record in records:
        container.add_record(record)

    for input_record, saved_record in zip(records, container.records):
        assert input_record.data == saved_record.finalize_record().data

    df = pd.DataFrame({"b": [1000, 2000]})
    container.update_with_dataframe(df)

    assert container.records[0].finalize_record().data == {"a": 123, "b": 1000}
    assert container.records[1].finalize_record().data == {"a": 456, "b": 2000}

    df = pd.DataFrame({"b": [1000, 2000, 3000]})
    with pytest.raises(ValueError):
        container.update_with_dataframe(df)

    df = pd.DataFrame({"d": [1000, 2000]})
    with pytest.raises(RuntimeError):
        container.update_with_dataframe(df)

    container.clear_records()
    assert len(container.records) == 0
def test_simple_parsed_record_container():
    record_info = RecordInfo(AlteryxEngine())
    record_info.add_field(field_name="a", field_type=FieldType.byte)
    record_info.add_field(field_name="b", field_type=FieldType.fixeddecimal)

    container = ParsedRecordContainer(record_info)

    record1 = RecordRef(record_info)
    record1.data["a"] = 123
    record1.data["b"] = 666.666

    record2 = RecordRef(record_info)
    record2.data["a"] = 456
    record2.data["b"] = 999.999

    records = [record1, record2]

    for record in records:
        container.add_record(record)

    df = container.build_dataframe()
    assert df.equals(pd.DataFrame({"a": [123, 456], "b": [666.666, 999.999]}))
예제 #9
0
def test_field_proxy():
    record_info = RecordInfo(AlteryxEngine())
    record_info.add_field(
        field_name="float",
        field_type=FieldType.float,
        size=1,
        scale=1,
        source="test.txt",
        description="Test description",
    )

    field_proxy = FieldProxy(record_info.fields[0])

    record_creator = RecordCreator(record_info)
    assert field_proxy.name == "float"

    field_proxy.set(record_creator, "10.0")
    assert field_proxy.get(record_creator.finalize_record()) == 10.0

    field_proxy.set(record_creator, NULL_VALUE_PLACEHOLDER)
    assert field_proxy.get(record_creator.finalize_record()) is None

    field_proxy.set_null(record_creator)
    assert field_proxy.get(record_creator.finalize_record()) is None
예제 #10
0
 def generate_interview_fields(self, record: Sdk.RecordInfo,
                               source: str) -> List[Sdk.Field]:
     return [
         record.add_field("Glassdoor ID", Sdk.FieldType.v_wstring, 10, 0,
                          source, ''),
         record.add_field("Company Name", Sdk.FieldType.v_wstring, 100, 0,
                          source, ''),
         record.add_field("Date", Sdk.FieldType.v_wstring, 20, 0, source,
                          ''),
         record.add_field("Title (Analyst Interview)",
                          Sdk.FieldType.v_wstring, 256, 0, source, ''),
         record.add_field("Experience", Sdk.FieldType.v_wstring, 20, 0,
                          source, ''),
         record.add_field("Offer", Sdk.FieldType.v_wstring, 20, 0, source,
                          ''),
         record.add_field("Difficulty", Sdk.FieldType.v_wstring, 20, 0,
                          source, ''),
         record.add_field("Getting an interview", Sdk.FieldType.v_wstring,
                          20, 0, source, ''),
         record.add_field("Application", Sdk.FieldType.v_wstring, 5000, 0,
                          source, ''),
         record.add_field("Interview (description/verbatim)",
                          Sdk.FieldType.v_wstring, 5000, 0, source, ''),
         record.add_field("Interview (Questions)", Sdk.FieldType.v_wstring,
                          5000, 0, source, ''),
     ]
예제 #11
0
 def generate_review_fields(self, record: Sdk.RecordInfo,
                            source: str) -> List[Sdk.Field]:
     return [
         record.add_field("Glassdoor ID", Sdk.FieldType.v_wstring, 10, 0,
                          source, ''),
         record.add_field("Company Name", Sdk.FieldType.v_wstring, 100, 0,
                          source, ''),
         record.add_field("Review Date", Sdk.FieldType.v_wstring, 20, 0,
                          source, ''),
         record.add_field("Helpful (count)", Sdk.FieldType.v_wstring, 10, 0,
                          source, ''),
         record.add_field("Title (of the review)", Sdk.FieldType.v_wstring,
                          256, 0, source, ''),
         record.add_field("Rating (out of 5)", Sdk.FieldType.v_wstring, 3,
                          0, source, ''),
         record.add_field("Current/ Past Employee", Sdk.FieldType.v_wstring,
                          10, 0, source, ''),
         record.add_field("Employee Title", Sdk.FieldType.v_wstring, 100, 0,
                          source, ''),
         record.add_field("Employment Type", Sdk.FieldType.v_wstring, 100,
                          0, source, ''),
         record.add_field("Location", Sdk.FieldType.v_wstring, 100, 0,
                          source, ''),
         record.add_field("Recommends", Sdk.FieldType.v_wstring, 10, 0,
                          source, ''),
         record.add_field("Positive Outlook", Sdk.FieldType.v_wstring, 10,
                          0, source, ''),
         record.add_field("Approves of CEO", Sdk.FieldType.v_wstring, 10, 0,
                          source, ''),
         record.add_field("Time Employed", Sdk.FieldType.v_wstring, 100, 0,
                          source, ''),
         record.add_field("Pros", Sdk.FieldType.v_wstring, 5000, 0, source,
                          ''),
         record.add_field("Cons", Sdk.FieldType.v_wstring, 5000, 0, source,
                          ''),
         record.add_field("Advice to Management", Sdk.FieldType.v_wstring,
                          5000, 0, source, '')
     ]