Skip to main content
Announcements
Global Transformation Awards submissions are open! SUBMIT YOUR STORY
cancel
Showing results for 
Search instead for 
Did you mean: 
curiousfellow
Specialist
Specialist

new table when using applymap with resident

In some examples of how to use applymap tables are "resused".

In   Don't join - use Applymap instead

the code is  :

Orders :

Load *

Applymap .......

from Orders ;

When I do the same I get a second table with the same name added "-1" to it.

Only difference in my script is that I load from a resident table.

Is it not possible to add a field with applymap to a resident table ?

9 Replies
sunny_talwar

Not sure I understand the issue? In the attached application what issue have you been facing?

alexandros17
Partner - Champion III
Partner - Champion III

Use the noconcatenate Function:

addres_New: noconcatenate

load *,

Applymap('map_city_to_addres',number,null()) as city

resident address

drop table address;

let me know

jonathandienst
Partner - Champion III
Partner - Champion III

That's because you are changing the schema while using the same table name. You will need to explicitly concatenate:

concatenate(Orders)

Load *

Applymap .......

from Orders ;

The problem has nothing to do with the applymap.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
MindaugasBacius
Partner - Specialist III
Partner - Specialist III

I am not sure if you really need such a script.

Maybe that's a special needs for your Data model but I would rather make it more clean:

map_city_to_addres:

Mapping LOAD * INLINE [

    number, city

    1, city1

    2, city2

    3, city3

    4, city4

    5, city5

];

address:

LOAD *,

Applymap('map_city_to_addres',number,null()) as city

INLINE [

number,addres

1,address1

2,address2

3,address3

4,address4

5,address5

];

Table view:

Screenshot_1.jpg

curiousfellow
Specialist
Specialist
Author

I think I really need the script

This code script is a simplified version of the real script.

In my case I need to resuse the table to add fields to it.

MindaugasBacius
Partner - Specialist III
Partner - Specialist III

Try like this maybe:

address:

LOAD * INLINE [

number,addres

1,address1

2,address2

3,address3

4,address4

5,address5

];

city:

LOAD * INLINE [

    number, city

    1, city1

    2, city2

    3, city3

    4, city4

    5, city5

];

map_city_to_addres:

Mapping Load number, city resident city;

QUALIFY *;

addres:

load *,

Applymap('map_city_to_addres',number,null()) as city

resident address;

UNQUALIFY *;

drop table city;

Result:

Screenshot_1.jpg

Or instead of Qualify rename the fields.

rubenmarin

Hi, in case it helps: You can use several Applymap in the same LOAD sentence, and also you can use AplpyMap inseide an applymap:

LOAD *,

     Applymap('Map_City', FieldID) as City,

     Applymap('Map_Country', Applymap('Map_City', FieldID)) as Country,

Another technique is using precedent load, wich one load uses the data from the LOAD after it:

LOAD *, ApplyMap('Map_Country', City) as Country; // Here City field is used. (And loaded because of '*')

LOAD *, Applymap('Map_City', FieldID) as City  // Here City field is generated

curiousfellow
Specialist
Specialist
Author

When I use your suggestion , new rows are added. I want the city added to the row with the corresponding number in table address.

curiousfellow
Specialist
Specialist
Author

Sorry for not being clear. What i want to prevent is that a new table is being created.

In the script of Henric Cronström, will there a new table Orders-1 be created ?