use of org.pentaho.metadata.model.concept.types.DataType in project data-access by pentaho.
the class MetadataServiceUtil method convertQuery.
/**
* Converts a thin query model into a full query
*
* @param src
* @return
*/
public org.pentaho.metadata.query.model.Query convertQuery(Query src) {
IMetadataDomainRepository domainRepository = getMetadataRepository();
Domain fullDomain = domainRepository.getDomain(src.getDomainName());
LogicalModel logicalModel = fullDomain.findLogicalModel(src.getModelId());
// create a new full query object
org.pentaho.metadata.query.model.Query dest = new org.pentaho.metadata.query.model.Query(fullDomain, logicalModel);
// now add the selections
List<Selection> selections = dest.getSelections();
for (Column column : src.getColumns()) {
// get the objects needed for the selection
LogicalColumn logicalColumn = logicalModel.findLogicalColumn(column.getId());
org.pentaho.metadata.model.Category category = getCategory(column.getId(), logicalModel);
AggregationType aggregationType = AggregationType.valueOf(column.getSelectedAggType());
// create a selection and add it to the list
Selection selection = new Selection(category, logicalColumn, aggregationType);
selections.add(selection);
}
// now add the filters
List<Constraint> constraints = dest.getConstraints();
for (Condition condition : src.getConditions()) {
org.pentaho.metadata.query.model.CombinationType combinationType = CombinationType.valueOf(condition.getCombinationType());
LogicalColumn logicalColumn = logicalModel.findLogicalColumn(condition.getColumn());
String paramName = null;
for (Parameter parameter : src.getParameters()) {
if (parameter.getColumn().equals(condition.getColumn())) {
paramName = parameter.getName() == null ? parameter.getColumn() : parameter.getName();
}
}
// condition.setParameterized(parameterized);
String formula = condition.getCondition(logicalColumn.getDataType().name(), paramName);
Constraint constraint = new Constraint(combinationType, formula);
constraints.add(constraint);
}
// now set the disable distinct option
if (src.getDisableDistinct() != null) {
dest.setDisableDistinct(src.getDisableDistinct());
}
// now add the sorting information
List<org.pentaho.metadata.query.model.Order> orders = dest.getOrders();
for (Order order : src.getOrders()) {
// find the selection
for (Selection selection : selections) {
if (selection.getLogicalColumn().getId().equals(order.getColumn())) {
Type type = Type.valueOf(order.getOrderType());
org.pentaho.metadata.query.model.Order fullOrder = new org.pentaho.metadata.query.model.Order(selection, type);
orders.add(fullOrder);
}
}
}
// now add the parameter information
List<org.pentaho.metadata.query.model.Parameter> parameters = dest.getParameters();
for (Parameter parameter : src.getParameters()) {
// find the column for this parameter
LogicalColumn logicalColumn = logicalModel.findLogicalColumn(parameter.getColumn());
DataType type = logicalColumn.getDataType();
String[] value = parameter.getValue();
org.pentaho.metadata.query.model.Parameter fullParam = new org.pentaho.metadata.query.model.Parameter(parameter.getColumn(), type, value[0]);
parameters.add(fullParam);
}
return dest;
}
use of org.pentaho.metadata.model.concept.types.DataType in project data-access by pentaho.
the class ConditionTest method testGetConditionWithParametersForAllDataTypes.
@Test
public void testGetConditionWithParametersForAllDataTypes() {
Operator[] operatorsType1Array = { Operator.GREATER_THAN, Operator.LESS_THAN, Operator.EQUAL, Operator.GREATOR_OR_EQUAL, Operator.LESS_OR_EQUAL };
for (Operator operator : operatorsType1Array) {
when(icondition.getOperator()).thenReturn(operator.toString());
for (DataType dataType : DataType.values()) {
if (dataType.getName().equals(DataType.STRING.getName()) && operator.equals(Operator.EQUAL)) {
// Exception for DataType STRING
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("[" + categoryName + "." + columnName + "] = [param:" + paramName + "]"));
} else if (dataType.getName().equals(DataType.DATE.getName())) {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("[" + categoryName + "." + columnName + "] " + operator.toString() + "DATEVALUE([param:" + values[0] + "])"));
} else {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("[" + categoryName + "." + columnName + "] " + operator.toString() + "[param:" + paramName + "]"));
}
}
}
for (DataType dataType : DataType.values()) {
when(icondition.getOperator()).thenReturn(Operator.EXACTLY_MATCHES.toString());
if (dataType.getName().equals(DataType.DATE.getName())) {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("[" + categoryName + "." + columnName + "] = \"DATEVALUE([param:" + values[0] + "])\""));
} else {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("[" + categoryName + "." + columnName + "] = " + "[param:" + paramName + "]"));
}
when(icondition.getOperator()).thenReturn(Operator.CONTAINS.toString());
if (dataType.getName().equals(DataType.DATE.getName())) {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("CONTAINS([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[0] + "])\")"));
} else {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("CONTAINS([" + categoryName + "." + columnName + "];" + "[param:" + paramName + "])"));
}
when(icondition.getOperator()).thenReturn(Operator.DOES_NOT_CONTAIN.toString());
if (dataType.getName().equals(DataType.DATE.getName())) {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("NOT(CONTAINS([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[0] + "])\"))"));
} else {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("NOT(CONTAINS([" + categoryName + "." + columnName + "];" + "[param:" + paramName + "]))"));
}
when(icondition.getOperator()).thenReturn(Operator.BEGINS_WITH.toString());
if (dataType.getName().equals(DataType.DATE.getName())) {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("BEGINSWITH([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[0] + "])\")"));
} else {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("BEGINSWITH([" + categoryName + "." + columnName + "];" + "[param:" + paramName + "])"));
}
when(icondition.getOperator()).thenReturn(Operator.ENDS_WITH.toString());
if (dataType.getName().equals(DataType.DATE.getName())) {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("ENDSWITH([" + categoryName + "." + columnName + "];\"DATEVALUE([param:" + values[0] + "])\")"));
} else {
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("ENDSWITH([" + categoryName + "." + columnName + "];" + "[param:" + paramName + "])"));
}
when(icondition.getOperator()).thenReturn(Operator.IS_NULL.toString());
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("ISNA([" + categoryName + "." + columnName + "])"));
when(icondition.getOperator()).thenReturn(Operator.IS_NOT_NULL.toString());
Assert.assertThat(icondition.getCondition(dataType.getName(), paramName), is("NOT(ISNA([" + categoryName + "." + columnName + "]))"));
}
}
use of org.pentaho.metadata.model.concept.types.DataType in project pentaho-kettle by pentaho.
the class DimensionTableDialog method addLogicalColumnToAttributesList.
private void addLogicalColumnToAttributesList(LogicalColumn column) {
TableItem item = new TableItem(wAttributes.table, SWT.NONE);
// name, description, physical column name, data type, length, precision, source db, source table, source column, conversion remarks
//
int col = 1;
item.setText(col++, Const.NVL(ConceptUtil.getName(column, locale), ""));
item.setText(col++, Const.NVL(ConceptUtil.getDescription(column, locale), ""));
item.setText(col++, ConceptUtil.getAttributeType(column).name());
item.setText(col++, Const.NVL((String) column.getProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME), ""));
DataType dataType = (DataType) column.getProperty(DefaultPropertyID.DATA_TYPE.getId());
item.setText(col++, dataType == null ? "" : dataType.name());
item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH), ""));
item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION), ""));
item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_DB), ""));
item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE), ""));
item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN), ""));
item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS), ""));
}
use of org.pentaho.metadata.model.concept.types.DataType in project pentaho-platform by pentaho.
the class PMDUIComponent method addColumn.
@SuppressWarnings("deprecation")
public void addColumn(final LogicalColumn column, final Element tableNode, final String locale) {
// $NON-NLS-1$
Element columnNode = tableNode.addElement("column");
if (column.getId() != null) {
// $NON-NLS-1$
columnNode.addElement("column_id").setText(column.getId());
}
if (column.getName(locale) != null) {
// $NON-NLS-1$
columnNode.addElement("column_name").setText(column.getName(locale));
}
if (column.getDescription(locale) != null) {
// $NON-NLS-1$
columnNode.addElement("column_description").setText(column.getDescription(locale));
}
if (column.getFieldType() != null) {
// TODO this should take a locale
String desc = column.getFieldType().getDescription();
desc = org.pentaho.pms.messages.Messages.getString(desc);
// $NON-NLS-1$
columnNode.addElement("column_field_type").setText(desc);
}
DataType dataType = column.getDataType();
if (dataType != null) {
// $NON-NLS-1$
columnNode.addElement("column_type").setText(dataType.getName());
}
if (column.getProperty("lookup") != null) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$
columnNode.addElement("column_lookup").setText("true");
}
}
use of org.pentaho.metadata.model.concept.types.DataType in project data-access by pentaho.
the class MetadataServiceUtil method createCdaJson.
/**
* Returns a CDA JSON representation of a query result set
*
* @param resultSet
* @return
* @throws JSONException
*/
public String createCdaJson(final IPentahoResultSet resultSet, String locale) throws JSONException {
if (resultSet == null) {
return null;
}
JSONObject json = new JSONObject();
// Generate the metadata
final JSONArray metadataArray = new JSONArray();
final int columnCount = resultSet.getColumnCount();
final int rowCount = resultSet.getRowCount();
for (int i = 0; i < columnCount; i++) {
JSONObject info = new JSONObject();
// $NON-NLS-1$
info.put("colIndex", i);
// $NON-NLS-1$
info.put("colName", resultSet.getMetaData().getColumnHeaders()[0][i]);
DataType type = (DataType) resultSet.getMetaData().getAttribute(0, i, IPhysicalColumn.DATATYPE_PROPERTY);
// $NON-NLS-1$
info.put("colType", type.getName().toUpperCase());
LocalizedString name = (LocalizedString) resultSet.getMetaData().getAttribute(0, i, Concept.NAME_PROPERTY);
if (name != null && locale != null) {
// $NON-NLS-1$
info.put("colLabel", name.getString(locale));
}
metadataArray.put(info);
}
// $NON-NLS-1$
json.put("metadata", metadataArray);
// add the rows of data
final JSONArray valuesArray = new JSONArray();
for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
final JSONArray rowArray = new JSONArray();
valuesArray.put(rowArray);
for (int colIdx = 0; colIdx < columnCount; colIdx++) {
rowArray.put(resultSet.getValueAt(rowIdx, colIdx));
}
}
// $NON-NLS-1$
json.put("resultset", valuesArray);
return json.toString();
}
Aggregations