Question: I am trying to load data into hive tables which is delimited by double pipe(||). When I try this :

Sample I/P: 

```
1405983600000||111.111.82.41||806065581||session-id

```

Creating table in hive: 

```
create table test_hive(k1 string, k2 string, k3 string, k4 string,) row format delimited fields terminated by '||' stored as textfile;

```

Loading data from text file:

```
load data local inpath '/Desktop/input.txt' into table test_hive;

```

When I do this it is storing data in the below format:

```
1405983600000 tabspace-as-second-column 111.111.82.41 tabspace-as-fourth-column

```

Where as I am expecting the data in table to be 

```
1405983600000 111.111.82.41 806065581 session-id

```

Kindly help me out I have tried different options on this but unable to resolve it

Answer: 
> 
> I think I should get deadlock in the first implementation because apple say :dispatch\_sync->Calling this function and targeting the current queue results in deadlock
> 
> 
> 

It's true if the queue is a serial queue. However, in this case, you are using global queue, thus deadlock never happen. So the difference is which thread will do `Download the image here sync downloading` in the global queue thread pool.

**First implementation**

```
main queue -----------+---------------------------------+-----------+------
         async(global)|                                 ^           |
                      v                       sync(main)|           v
global queue thread1  +-----+BLOCKED        +-----------+BLOCKED    +------
                sync(global)|               ^
                            v               |
global queue thread2        +---------------+

```

**Second implementation**

```
main queue -----------+---------------------------------+-----------+------
         async(global)|                                 ^           |
                      v                       sync(main)|           v
global queue thread1  +---------------------------------+BLOCKED    +------

```

But dispatch\_sync is not good idea in this case. <https://developer.apple.com/library/ios/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html>

> 
> Important: You should never call the dispatch\_sync or dispatch\_sync\_f function from a task that is executing in the same queue that you are planning to pass to the function. This is particularly important for serial queues, which are guaranteed to deadlock, but should also be avoided for concurrent queues.
> 
> 
> 

... Even though I can't find any evidence of `dispatch_sync should also be avoided for concurrent queues` from 
<http://opensource.apple.com/source/libdispatch/libdispatch-339.92.1/src/queue.c>
dispatch\_sync dispatch\_get\_main\_queue() done the action immediately.Because we are doing the cation in main queue.Here we are doing the UI updates and all that stuffs in lazy loading and asynchronous download etc.

Its related to GCD for more details please refer AppleDevelopers forum.

The main benefits of using dispatch\_sync is we can do the operation concurrently.