Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from anupama-pathirage/UpdateIter
Browse files Browse the repository at this point in the history
Fix Data Iterator to work with ballerina DataIterator
  • Loading branch information
lafernando authored Jan 2, 2018
2 parents 3255ea1 + ca5bb0c commit d16c7f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.Base64;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* This iterator wraps a cassandra data row.
Expand Down Expand Up @@ -72,37 +71,42 @@ public void close(boolean b) {
}

@Override
public String getString(String s) {
public String getString(int columnIndex) {
this.checkCurrentRow();
return this.current.getString(s);
return this.current.getString(columnIndex - 1);
}

@Override
public long getInt(String s) {
public long getInt(int columnIndex) {
this.checkCurrentRow();
return this.current.getInt(s);
return this.current.getInt(columnIndex - 1);
}

@Override
public double getFloat(String s) {
public double getFloat(int columnIndex) {
this.checkCurrentRow();
return this.current.getFloat(s);
return this.current.getFloat(columnIndex - 1);
}

@Override
public boolean getBoolean(String s) {
public boolean getBoolean(int columnIndex) {
this.checkCurrentRow();
return this.current.getBool(s);
return this.current.getBool(columnIndex - 1);
}

@Override
public String getBlob(String s) {
public String getBlob(int columnIndex) {
this.checkCurrentRow();
return getString(this.current.getBytes(s));
return getString(this.current.getBytes(columnIndex - 1));
}

@Override
public Map<String, Object> getArray(String s) {
public Object[] getStruct(int i) {
return new Object[0];
}

@Override
public Object[] getArray(int columnIndex) {
return null;
}

Expand All @@ -113,24 +117,26 @@ public BStruct generateNext() {
int doubleRegIndex = -1;
int stringRegIndex = -1;
int booleanRegIndex = -1;
int index = 0;
for (ColumnDefinition columnDef : columnDefs) {
String columnName = columnDef.getName();
TypeKind type = columnDef.getType();
++index;
switch (type) {
case STRING:
String sValue = getString(columnName);
String sValue = getString(index);
bStruct.setStringField(++stringRegIndex, sValue);
break;
case INT:
long lValue = getInt(columnName);
long lValue = getInt(index);
bStruct.setIntField(++longRegIndex, lValue);
break;
case FLOAT:
double fValue = getFloat(columnName);
double fValue = getFloat(index);
bStruct.setFloatField(++doubleRegIndex, fValue);
break;
case BOOLEAN:
boolean boolValue = getBoolean(columnName);
boolean boolValue = getBoolean(index);
bStruct.setBooleanField(++booleanRegIndex, boolValue ? 1 : 0);
break;
default:
Expand All @@ -145,6 +151,11 @@ public List<ColumnDefinition> getColumnDefinitions() {
return this.columnDefs;
}

@Override
public BStructType getStructType() {
return this.bStructType;
}

private void generateStructType() {
BType[] structTypes = new BType[columnDefs.size()];
BStructType.StructField[] structFields = new BStructType.StructField[columnDefs.size()];
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@

<properties>
<project.scm.id>my-scm-server</project.scm.id>
<ballerina.version>0.95.3</ballerina.version>
<ballerina.version>0.95.6</ballerina.version>
<cassandra.version>3.1.3</cassandra.version>
<com.google.guava.version>19.0</com.google.guava.version>
<io.dropwizard.metrics.version>3.1.2</io.dropwizard.metrics.version>
Expand Down

0 comments on commit d16c7f1

Please sign in to comment.