# Virtual graph import NPE

**URL:** https://community.stardog.com/t/virtual-graph-import-npe/827
**Category:** Bug
**Created:** [February 23, 2018, 3:40pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827 "2018-02-23T15:40:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)
#### Post date: [February 23, 2018, 3:40pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827/1 "2018-02-23T15:40:26Z")

</div>

Stardog 5.2.0

I’m getting a NPE when importing a virtual graph from mysql.

java.lang.NullPointerException at com.complexible.stardog.virttual.VirtualGraphIterator$MaterializationContext.getColumnIndex(VirtualGraphIterator.java:281)

…

An error occurred adding RDF to the index: null

I’m sorry that I can’t include the mappings, data or complete stack trace but I thought I’d report it anyway.

---

<div class="post-metadata">

### Author: ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)
#### Post date: [February 23, 2018, 3:49pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827/2 "2018-02-23T15:49:41Z")

</div>

Thanks. Do you have any quoted field names, eg ``field with space``? We did some work that may have fixed this in 5.2.1. Worth trying. The error message has been improved to indicate which field was not found which may help narrow down the issue.

Jess

---

<div class="post-metadata">

### Author: ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)
#### Post date: [February 23, 2018, 4:08pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827/3 "2018-02-23T16:08:42Z")

</div>

No quoted fields but I think I found out what the problem was. I was doing a join between two tables (actually a self join) and using the table alias in the mapping since there were duplicate column names. If I alias the columns and don't use the table alias it seems to work. This isn't the exact mapping but just a quick example.

The following doesn't work

> \<{a.id}\> a my:Thing  
> :has \<{b.id}\>  
> sm:map [  
> sm:query """  
> select  
> a.id,  
> b.id  
> from  
> mytable a  
> join  
> mytable b  
> on  
> a.id = b.otherid"""  
> ] .

while this does

> ```
> <{a_id}> a my:Thing
> :has <{b_id}>
> sm:map [
> sm:query """
> select
> a.id as a_id,
> b.id as b_id
> from
> mytable a
> join
> mytable b
> on
> a.id = b.otherid"""
> ] .
> 
> ```

Hopefully I captured that correctly.

---

<div class="post-metadata">

### Author: ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)
#### Post date: [February 23, 2018, 4:11pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827/4 "2018-02-23T16:11:14Z")

</div>

Thanks a lot for the illustration. I’ll dig into it. This is really helpful.

Jess

---

<div class="post-metadata">

### Author: ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)
#### Post date: [February 23, 2018, 4:19pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827/5 "2018-02-23T16:19:44Z")

</div>

Glad to be helpful. Quick follow up for you and anyone following.

It appears that aliasing one of the tables isn't sufficient. (I wasn't debugging but being lazy and seeing if I could save myself some typing 😉

So based on the example I gave the following wouldn't work either

> ```
> <{a_id}> a my:Thing
> :has <{b.id}>
> sm:map [
> sm:query """
> select
> a.id as a_id,
> b.id
> from
> mytable a
> join
> mytable b
> on
> a.id = b.otherid"""
> ] .
> 
> ```

---

<div class="post-metadata">

### Author: ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)
#### Post date: [February 23, 2018, 4:22pm UTC](https://community.stardog.com/t/virtual-graph-import-npe/827/6 "2018-02-23T16:22:20Z")

</div>

I _think_ this would work with a query but not with materialization (or `?s ?p ?o` query). We treat the field names literally during materialization but I guess we need to generate a better projection to properly resolve the fields and avoid any ambiguities.
