Kafka join streams filter by key - join

I did some very easy example with join streams where two topics have the simple key value structure (integer/string) and it's works perfectly.
May I ask, how can I do something like:
SELECT * FROM stream1, stream2
WHERE stream1.key = stream2.key AND (stream1.key > 50 && stream1.key < 100) AND (stream2.key > 50 AND stream2.key < 100)
Kafka allows something like this?
Finally what I want to do is to filter 2 joined streams where key will be GenericRecord and it will looks somehow:
SELECT * FROM stream1, stream2
WHERE stream1.genericRecordkey.someId. = stream2.genericRecordkey.someId
My test example:
public void joinKStreamToKStreamWhereKeyValueIsIntegerString() throws Exception {
String uniqueKey = new Object() {
}.getClass().getEnclosingMethod().getName();
long timestamp = new Date().getTime();
String firstTopic = String.format("%1$s_1_%2$s", uniqueKey, timestamp);
String secondTopic = String.format("%1$s_2_%2$s", uniqueKey, timestamp);
String outputTopic = String.format("%1$s_output_%2$s", uniqueKey, timestamp);
String appIdConfig = String.format("%1$s_app_id_%2$s", uniqueKey, timestamp);
String groupIdConfig = String.format("%1$s_group_id_%2$s", uniqueKey, timestamp);
List<KeyValue<Integer, String>> ikv1 = Arrays.asList(
new KeyValue<>(1, "Bruce Eckel"),
new KeyValue<>(2, "Robert Lafore"),
new KeyValue<>(3, "Andrew Tanenbaum")
);
List<KeyValue<Integer, String>> ikv2 = Arrays.asList(
new KeyValue<>(3, "Modern Operating System"),
new KeyValue<>(1, "Thinking in Java"),
new KeyValue<>(3, "Computer Architecture"),
new KeyValue<>(4, "Programming in Scala")
);
List<KeyValue<Integer, String>> expectedResults = Arrays.asList(
new KeyValue<>(3, "Andrew Tanenbaum/Modern Operating System"),
new KeyValue<>(1, "Bruce Eckel/Thinking in Java"),
new KeyValue<>(3, "Andrew Tanenbaum/Computer Architecture")
);
Integer partitions = 1;
Integer replication = 1;
Properties topicConfig = new Properties();
TopicUtils.createTopic(firstTopic, partitions, replication, topicConfig);
TopicUtils.createTopic(secondTopic, partitions, replication, topicConfig);
TopicUtils.createTopic(outputTopic, partitions, replication, topicConfig);
final Serde<String> stringSerde = Serdes.String();
final Serde<Integer> integerSerde = Serdes.Integer();
Properties streamsConfiguration = new Properties();
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, appIdConfig);
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS_CONFIG);
streamsConfiguration.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, ZOOKEEPER_CONNECT_CONFIG);
streamsConfiguration.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.Integer().getClass().getName());
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
// The commit interval for flushing records to state stores and downstream must be lower than
// this integration test's timeout (30 secs) to ensure we observe the expected processing results.
streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 10 * 1000);
streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
// Use a temporary directory for storing state, which will be automatically removed after the test.
streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getAbsolutePath());
KStreamBuilder builder = new KStreamBuilder();
KStream<Integer, String> firstStream = builder.stream(integerSerde, stringSerde, firstTopic);
KStream<Integer, String> secondStream = builder.stream(integerSerde, stringSerde, secondTopic);
KStream<Integer, String> outputStream = firstStream.join(secondStream, (l, r) -> {
return l + "/" + r;
}, JoinWindows.of(TimeUnit.SECONDS.toMillis(5)), integerSerde, stringSerde, stringSerde);
outputStream.to(integerSerde, stringSerde, outputTopic);
KafkaStreams streams = new KafkaStreams(builder, streamsConfiguration);
streams.start();
Properties pCfg1 = new Properties();
pCfg1.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS_CONFIG);
pCfg1.put(ProducerConfig.ACKS_CONFIG, "all");
pCfg1.put(ProducerConfig.RETRIES_CONFIG, 0);
pCfg1.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class);
pCfg1.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
IntegrationTestUtils.produceKeyValuesSynchronously(firstTopic, ikv1, pCfg1);
Properties pCfg2 = new Properties();
pCfg2.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS_CONFIG);
pCfg2.put(ProducerConfig.ACKS_CONFIG, "all");
pCfg2.put(ProducerConfig.RETRIES_CONFIG, 0);
pCfg2.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class);
pCfg2.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
IntegrationTestUtils.produceKeyValuesSynchronously(secondTopic, ikv2, pCfg2);
Properties consumerConfig = new Properties();
consumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS_CONFIG);
consumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, groupIdConfig);
consumerConfig.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
consumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, IntegerDeserializer.class);
consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
List<KeyValue<Integer, String>> actualResults = IntegrationTestUtils.waitUntilMinKeyValueRecordsReceived(consumerConfig, outputTopic, expectedResults.size());
streams.close();
assertThat(actualResults).containsExactlyElementsOf(expectedResults);
}
Hope I explained well and thanks for any help.

You can just apply a filter before you do the join.
outputStream = firstStream.filter(...).join(secondStream.filter(...), ...);
If you want to join on stream1.genericRecordkey.someId you will need to extract someId first and set it as key:
firstStream.selectKey((k,v) -> v.someId) ).join(secondStream.selectKey((k,v) -> v.someId), ...);
For more details, check out the docs: http://docs.confluent.io/current/streams/developer-guide.html

Related

retrieve checkbox values and mark as checked

i'm trying to retrieve options from database to checkbox and if it has the same product ID it has to be checked by default
this is the insert code to database
for (int i = 0; i < ddlcaroptions.Items.Count; i++)
{
if (ddlcaroptions.Items[i].Selected == true)
{
Int64 PCarOptionID = Convert.ToInt64(ddlcaroptions.Items[i].Value);
SqlCommand cmd2 = new SqlCommand("insert into tblCarOptionQuant values('" + PID + "','" + PCarOptionID + "')", con);
cmd2.ExecuteNonQuery();
}
}
it works fine now i want to edit this checkbox and update database
now i bind the checkbox from another table that has name and values
SqlCommand cmd = new SqlCommand("select * from tblCarOption", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count != 0)
{
ddlcaroptions.DataSource = dt;
ddlcaroptions.DataTextField = "CarOptionNameAR";
ddlcaroptions.DataValueField = "CarOptionID";
ddlcaroptions.DataBind();
}
now i have all the options but i want the selected values to be the ones that user already checked before and saved in tblCarOptionQuant table,
i tried to get the values by this command
using (SqlCommand getselectedop = new SqlCommand("select PCarOptionID from tblCarOptionQuant where PID = " + PID + "", con))
its okay but now what can i do to set selected values from this command result !??
you can use FindByValue to get the specific item and set it to selected, refer the code below
string value = "SomeValue";
var item = ddlcompany.Items.FindByValue(value);
if (item != null)
item.Selected = true;
the problem is when you retrieve data and convert to string you get only 1st row so i used StringBuilder to build 1 string has all rows in table :)
!! Attention !!
before you use this code make sure you bind your checkbox with all the values that user checked or not ,, then use this code to get the options that selected before (by the user)
using (SqlCommand getselectedop = new SqlCommand("RetrieveCarOptions", con))
{
getselectedop.CommandType = CommandType.StoredProcedure;
getselectedop.Parameters.AddWithValue("#PID", Convert.ToInt64(Request.QueryString["PID"]));
con.Open();
using (SqlDataReader reader = getselectedop.ExecuteReader())
{
StringBuilder sb = new StringBuilder();
if (reader.HasRows)
{
if (sb.Length > 0) sb.Append("___");
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
if (reader.GetValue(i) != DBNull.Value)
sb.AppendFormat("{0}-", Convert.ToString(reader.GetValue(i)));
SelectCheckBoxList(reader["PCarOptionID"].ToString(), ddlcaroptions);
}
}
}
}
now split and check if it has the same value to mark as checked
private void SelectCheckBoxList(string valueToSelect, CheckBoxList ddlcaroptions)
{
string[] aray = valueToSelect.Split(',');
foreach (string listItem2 in aray)
{
ListItem listItem = ddlcaroptions.Items.FindByValue(valueToSelect);
listItem.Selected = true;
}
}
i hope this answer is clear and help someone else :)

getting the System.Threading.Tasks.Task`1[System.Int32] error

i am trying to convert my code to a sync but when i run it
i get in one of my vars the value "System.Threading.Tasks.Task`1[System.Int32]" instead of the expected ans
i have read most of the same questions asked in this topic but none of them helped me solved the problem
i tried to use properly the await but its isn't helped
public async Task<int> userloginAsync(string name,string pass)
{
using (SqlConnection con = new SqlConnection(#"/////:P//////"))
{
using (SqlCommand cmd = new SqlCommand("UserLoginPro"))
{
cmd.Connection = con;
cmd.CommandText = "SELECT count(id) FROM user_table where name =#name and password =#password; ";
cmd.Parameters.AddWithValue("#name", name);
cmd.Parameters.AddWithValue("#password", pass);
await con.OpenAsync();
var ans1 = await cmd.ExecuteScalarAsync();
var ans = ans1.ToString();
con.Close();
int res = Convert.ToInt32(ans);
con.Close();
return res;
}
}
}
its should query the mssql if there is an match to inputs(username and password)
and if there is return 1
if not 0
(in the DB there is unique usernames so it can be only one )

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '{'

I am new to java.We have a few tabled valued parameter used in one of our stored procedure when we try with below code then we are getting following error.
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near
'{'.
import java.sql.*;
import com.microsoft.sqlserver.jdbc.SQLServerDataTable; import
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
public class DB_SP_Call {
Connection conn = null;
Statement stmt = null;
String dbserver="10.42..:1198";
String db="t1c";
String USER="t1c";
String PWD="t1c";
String sql; static final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; public void
runSP(){
String DB_URL = "jdbc:sqlserver://"+dbserver+";databaseName="+db; try{
Class.forName(JDBC_DRIVER);
//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PWD);
System.out.println("Creating statement...");
stmt = conn.createStatement();
//SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement)conn.prepareStatement("{call exec
t1c.scnTargetingBYO
#InstrID=?,#CAS=?,#PageNum=?,#PageSize=?,#SortField=?,#TotalRecNum=?
output,#OutputFirmFund=?,#Download=?,#FirmContactData=?,#FirmList=?,#CustTagList=?,#LocationList=?,#Orientation=?,#InvTypeIDList=?,#InvStyleIDList=?,#AdvisoryList=?,#SocialyResposible=?,#TurnoverList=?,#SecurityActivity=?,#InstWithUpside=?,#MarketCapPass=?,#PNI=?,#EventFirmMet=?,#EventType=?,#CorpParticipant=?,#SectorList=?,#GeoIDList=?,#MarketCapStr=?,#HoldType=?,#ActThreshold=?,#SavedDataFlag=?
output,#DisplayGroupFlag=?,#PerPeerFlag=?,#UserId=?,#AccountID=?}");
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement)conn.prepareStatement("{ call exec
t1c.scnTargetingBYO
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
}");
pstmt.setInt(1, 264998);
pstmt.setString(2, "P");
pstmt.setInt(3,0);
pstmt.setInt(4, 100);
pstmt.setString(5, "Pos DESC");
pstmt.setInt(6, 2308);
pstmt.setInt(7,0);
pstmt.setInt(8, 0);
pstmt.setInt(9, 0);
SQLServerDataTable p10 = new SQLServerDataTable();
p10.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p10.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
pstmt.setStructured(10, "t1c.InvIDTabType", p10);
SQLServerDataTable p11 = new SQLServerDataTable();
p11.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p11.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
pstmt.setStructured(11, "t1c.InvIDTabType", p11);
SQLServerDataTable p12 = new SQLServerDataTable();
p12.addColumnMetadata("LocationID",java.sql.Types.NUMERIC);
p12.addColumnMetadata("LocationTypeID",java.sql.Types.NUMERIC);
Object[] row= new Object[2];
row[0]=new Integer(10006);
row[1]=new Integer(5);
p12.addRow(row);
pstmt.setStructured(12, "t1c.LocationList", p12);
pstmt.setInt(13,1);
SQLServerDataTable p14 = new SQLServerDataTable();
p14.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p14.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
p14.addColumnMetadata("Lev",java.sql.Types.NUMERIC);
Object[] row1= new Object[3];
row1[0]=new Integer(200);
row1[1]=null;
row1[2]=new Integer(2);
p14.addRow(row1);
Object[] row2= new Object[3];
row2[0]=new Integer(600);
row2[1]=null;
row2[2]=new Integer(1);
p14.addRow(row2);
Object[] row3= new Object[3];
row3[0]=new Integer(100);
row3[1]=null;
row3[2]=new Integer(2);
p14.addRow(row3);
Object[] row4= new Object[3];
row4[0]=new Integer(500);
row4[1]=null;
row4[2]=new Integer(1);
p14.addRow(row4);
Object[] row5= new Object[3];
row5[0]=new Integer(300);
row5[1]=null;
row5[2]=new Integer(2);
p14.addRow(row5);
pstmt.setStructured(14, "t1c.InvIDTabType2", p14);
SQLServerDataTable p15 = new SQLServerDataTable();
p15.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p15.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
p15.addColumnMetadata("Lev",java.sql.Types.NUMERIC);
pstmt.setStructured(15, "t1c.InvIDTabType2", p15);
pstmt.setInt(16,0);
pstmt.setString(17,"NULL");
SQLServerDataTable p18 = new SQLServerDataTable();
p18.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p18.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
pstmt.setStructured(18, "t1c.InvIDTabType", p18);
pstmt.setInt(19,0);
pstmt.setInt(20,0);
pstmt.setInt(21,0);
pstmt.setInt(22,0);
pstmt.setInt(23,3);
SQLServerDataTable p24 = new SQLServerDataTable();
p24.addColumnMetadata("EventID",java.sql.Types.NUMERIC);
p24.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p24.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
pstmt.setStructured(24, "cms.EvtLinkTabType", p24);
SQLServerDataTable p25 = new SQLServerDataTable();
p25.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p25.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
pstmt.setStructured(25, "t1c.InvIDTabType", p25);
SQLServerDataTable p26 = new SQLServerDataTable();
p26.addColumnMetadata("Type",java.sql.Types.VARCHAR);
p26.addColumnMetadata("ID",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID3",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID4",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID5",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID6",java.sql.Types.NUMERIC);
p26.addColumnMetadata("ID7",java.sql.Types.NUMERIC);
pstmt.setStructured(26, "t1c.InvSpecialIDTabType2", p26);
SQLServerDataTable p27 = new SQLServerDataTable();
p27.addColumnMetadata("Type",java.sql.Types.VARCHAR);
p27.addColumnMetadata("ID",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID3",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID4",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID5",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID6",java.sql.Types.NUMERIC);
p27.addColumnMetadata("ID7",java.sql.Types.NUMERIC);
pstmt.setStructured(27, "t1c.InvSpecialIDTabType2", p27);
pstmt.setString(28,"NULL");
pstmt.setInt(29,1);
SQLServerDataTable p30 = new SQLServerDataTable();
p30.addColumnMetadata("Category", java.sql.Types.VARCHAR);
p30.addColumnMetadata("ActType", java.sql.Types.NUMERIC);
p30.addColumnMetadata("Threshold", java.sql.Types.VARCHAR);
p30.addColumnMetadata("Min", java.sql.Types.NUMERIC);
p30.addColumnMetadata("Max", java.sql.Types.NUMERIC);
Object[] row6= new Object[5];
row6[0]=new String("O");
row6[1]=new Integer(0);
row6[2]=new String("S");
row6[3]=new Integer(1);
row6[4]=null;
p30.addRow(row6);
Object[] row7= new Object[5];
row7[0]=new String("F");
row7[1]=null;
row7[2]=new String("E");
row7[3]=new Integer(5);
row7[4]=null;
p30.addRow(row7);
pstmt.setStructured(30, "t1c.InvActThresholdTabType", p30);
pstmt.setInt(31,2);
pstmt.setInt(32,2946);
pstmt.setInt(33,0);
pstmt.setInt(34,234568);
pstmt.setInt(35,21022);
ResultSet rs = pstmt.executeQuery();
//ResultSet rs = pstmt.execute();
ResultSetMetaData metaData = rs.getMetaData();
//System.out.println("Hi, fetching resultset.........");
System.out.println(metaData.getColumnCount());
while(rs.next()){
int intdata = rs.getInt("LgcyInvestorID");
System.out.println(intdata);
}
}catch(Exception e){ e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}
catch(SQLException se2)
{
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}
}
public static void main(String[] args) {
DB_SP_Call dbcall= new DB_SP_Call();
dbcall.runSP(); }
}
Request experts to please help in this regard.

Avro serialization hanging on DataFileWriter close method

I am trying to use avro serialization but when I have multiple records to serialize, the application hangs on DataFileWriter close method, however it works with a small amount of records.
final PipedOutputStream pipedOutputStream = new PipedOutputStream();
PipedInputStream pipedInputStream = new PipedInputStream(
pipedOutputStream);
DatumWriter<DW> userDatumWriter = new SpecificDatumWriter<DW>(DW.class);
DataFileWriter<DW> dataFileWriter = new DataFileWriter<DW>(
userDatumWriter);
dataFileWriter.create(payload.get(0).getSchema(), pipedOutputStream);
for (DW currentRecord : payload) {
dataFileWriter.append(currentRecord);
}
dataFileWriter.close();
return pipedInputStream;
I tried to flush after adding 10 records at a time, but then it hangs on the flush method.
Can anyone help me with this?
Solved by returning a ByteArrayOutputStream as follows:
Schema schema = ReflectData.get().getSchema(DW.class);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ReflectDatumWriter<Object> reflectDatumWriter = new ReflectDatumWriter<Object>(
schema);
DataFileWriter<Object> writer = new DataFileWriter<Object>(
reflectDatumWriter).create(schema, outputStream);
for (DW currentRecord : payload) {
writer.append(currentRecord);
}
writer.close();
return outputStream.toByteArray();

HOW to MERGE in neo4j using JAVA

Hi I am trying to insert two properties of a node....I am trying like below..
I am trying to add two properties to CUSTOMER NODE
1.name and 2.TOTAL_CALL_DURATION
How can I add two properties
try ( Transaction tx = graphDb.beginTx() )
{
String queryString = "MERGE (n:CUSTOMER {name:{name},TOTAL_CALL_DURATION:{TOTAL_CALL_DURATION}}) RETURN n";
Map<String, Object> callerProperties = new HashMap<>();
callerProperties.put( "name", callerName );
callerProperties.put("TOTAL_CALL_DURATION", 120);
resultIterator_caller = execEngine.execute( queryString, callerProperties ).columnAs( "n" );
tx.success();
}
The error I am getting like below:
Exception in thread "main" org.neo4j.cypher.ParameterNotFoundException: Expected a parameter named TOTAL_CALL_DURATION
at org.neo4j.cypher.internal.compiler.v2_1.pipes.QueryState$$anonfun$getParam$1.apply(QueryState.scala:45)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.QueryState$$anonfun$getParam$1.apply(QueryState.scala:45)
at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
at scala.collection.AbstractMap.getOrElse(Map.scala:58)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.QueryState.getParam(QueryState.scala:45)
at org.neo4j.cypher.internal.compiler.v2_1.commands.expressions.ParameterExpression.apply(ParameterExpression.scala:27)
at org.neo4j.cypher.internal.compiler.v2_1.helpers.PropertySupport$$anonfun$firstNullPropertyIfAny$1.isDefinedAt(PropertySupport.scala:29)
at org.neo4j.cypher.internal.compiler.v2_1.helpers.PropertySupport$$anonfun$firstNullPropertyIfAny$1.isDefinedAt(PropertySupport.scala:28)
at scala.collection.TraversableOnce$$anonfun$collectFirst$1.apply(TraversableOnce.scala:132)
at scala.collection.TraversableOnce$$anonfun$collectFirst$1.apply(TraversableOnce.scala:131)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.collectFirst(TraversableOnce.scala:131)
at scala.collection.AbstractTraversable.collectFirst(Traversable.scala:105)
at org.neo4j.cypher.internal.compiler.v2_1.helpers.PropertySupport$.firstNullPropertyIfAny(PropertySupport.scala:28)
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergeNodeAction.ensureNoNullNodeProperties(MergeNodeAction.scala:95)
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergeNodeAction.exec(MergeNodeAction.scala:73)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPipe.org$neo4j$cypher$internal$compiler$v2_1$pipes$ExecuteUpdateCommandsPipe$$exec(ExecuteUpdateCommandsPipe.scala:57)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPi$$$$1019fdff8b266d7d9d5647386930b3d8$$$$ands$1$$anonfun$apply$2.apply(ExecuteUpdateCommandsPipe.scala:46)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPi$$$$1019fdff8b266d7d9d5647386930b3d8$$$$ands$1$$anonfun$apply$2.apply(ExecuteUpdateCommandsPipe.scala:46)
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply$mcZ$sp(ClosingIterator.scala:37)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:34)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:34)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$failIfThrows$1.apply(ClosingIterator.scala:93)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.decoratedCypherException(ClosingIterator.scala:102)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.failIfThrows(ClosingIterator.scala:91)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.hasNext(ClosingIterator.scala:34)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.foreach(ClosingIterator.scala:28)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:176)
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.to(ClosingIterator.scala:28)
at scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:257)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.toList(ClosingIterator.scala:28)
at org.neo4j.cypher.internal.compiler.v2_1.EagerPipeExecutionResult.<init>(EagerPipeExecutionResult.scala:32)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1$$anonfun$apply$2.apply(ExecutionPlanBuilder.scala:125)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1$$anonfun$apply$2.apply(ExecutionPlanBuilder.scala:119)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionWorkflowBuilder.runWithQueryState(ExecutionPlanBuilder.scala:168)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1.apply(ExecutionPlanBuilder.scala:118)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1.apply(ExecutionPlanBuilder.scala:103)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:68)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:67)
at org.neo4j.cypher.internal.ExecutionPlanWrapperForV2_1.execute(CypherCompiler.scala:159)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:76)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:71)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:84)
at com.emc.neo4jConnectivity.NodeCreation.createNodes(NodeCreation.java:84)
at com.emc.neo4jConnectivity.NodeCreation.main(NodeCreation.java:136)
There's nothing wrong with your code, I've converted it into a self-contained groovy script running fine without any errors.
Try to provide a minimal viable testcase showing the error you're observing
For reference, here's the script:
#Grapes([
#Grab(group="org.neo4j", module="neo4j-kernel", version="2.1.8", classifier="tests"),
#Grab(group="org.neo4j", module="neo4j-kernel", version="2.1.8"),
#Grab(group="org.neo4j", module="neo4j-cypher", version="2.1.8")
])
import org.neo4j.test.TestGraphDatabaseFactory
import org.neo4j.cypher.javacompat.ExecutionEngine
import org.neo4j.helpers.collection.IteratorUtil
def graphDb = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase()
def executionEngine = new ExecutionEngine(graphDb)
def resultIterator_caller
def tx = graphDb.beginTx()
try {
String queryString = "MERGE (n:CUSTOMER {name:{name},TOTAL_CALL_DURATION:{TOTAL_CALL_DURATION}}) RETURN n";
Map<String, Object> callerProperties = new HashMap<>();
callerProperties.put( "name", "abc" );
callerProperties.put("TOTAL_CALL_DURATION", 120);
resultIterator_caller = executionEngine.execute( queryString, callerProperties ).columnAs( "n" );
tx.success()
} finally {
tx.close()
}
// we need another tx to consume the result (since we're returning node instances)
transaction = graphDb.beginTx()
try {
assert resultIterator_caller.hasNext()
def nextNode = resultIterator_caller.next()
assert nextNode.getProperty("name",null) == "abc"
assert nextNode.getProperty("TOTAL_CALL_DURATION",null) == 120
assert !resultIterator_caller.hasNext()
tx.success()
} finally {
tx.close()
}

Resources