public static LinkedHashMap<String, Object> buildType(List<ColumnDesc> columns, Set<String> copyFrom, ClasspathImportServiceCompileTime classpathImportService, EventTypeNameResolver eventTypeResolver) throws ExprValidationException { LinkedHashMap<String, Object> typing = new LinkedHashMap<String, Object>(); Set<String> columnNames = new HashSet<String>(); // Copy-from information gets added first as object-array appends information in well-defined order if (copyFrom != null && !copyFrom.isEmpty()) { for (String copyFromName : copyFrom) { EventType type = eventTypeResolver.getTypeByName(copyFromName); if (type == null) { throw new ExprValidationException("Type by name '" + copyFromName + "' could not be located"); } mergeType(typing, type, columnNames); } } for (ColumnDesc column : columns) { boolean added = columnNames.add(column.getName()); if (!added) { throw new ExprValidationException("Duplicate column name '" + column.getName() + "'"); } Object columnType = buildType(column, classpathImportService); typing.put(column.getName(), columnType); } return typing; }
private void validateKeyTypes(List<CreateTableColumn> columns, ClasspathImportServiceCompileTime classpathImportService) throws ExprValidationException { for (CreateTableColumn col : columns) { if (col.getPrimaryKey() == null || !col.getPrimaryKey()) { continue; } String msg = "Column '" + col.getColumnName() + "' may not be tagged as primary key"; if (col.getOptExpression() != null) { throw new ExprValidationException(msg + ", an expression cannot become a primary key column"); } Object type = EventTypeUtility.buildType(new ColumnDesc(col.getColumnName(), col.getOptType().toEPL()), classpathImportService); if (!(type instanceof Class)) { throw new ExprValidationException(msg + ", received unexpected event type '" + type + "'"); } if (((Class) type).isArray()) { throw new ExprValidationException(msg + ", an array-typed column cannot become a primary key column"); } } }
private List<TableColumnDesc> validateExpressions(List<CreateTableColumn> columns, StatementCompileTimeServices services) throws ExprValidationException { Set<String> columnNames = new HashSet<>(); List<TableColumnDesc> descriptors = new ArrayList<>(); int positionInDeclaration = 0; for (CreateTableColumn column : columns) { String msgprefix = "For column '" + column.getColumnName() + "'"; // check duplicate name if (columnNames.contains(column.getColumnName())) { throw new ExprValidationException("Column '" + column.getColumnName() + "' is listed more than once"); } columnNames.add(column.getColumnName()); // determine presence of type annotation EventType optionalEventType = validateExpressionGetEventType(msgprefix, column.getAnnotations(), services); // aggregation node TableColumnDesc descriptor; if (column.getOptExpression() != null) { ExprAggregateNode validated = validateAggregationExpr(column.getOptExpression(), optionalEventType, services); descriptor = new TableColumnDescAgg(positionInDeclaration, column.getColumnName(), validated, optionalEventType); } else { Object unresolvedType = EventTypeUtility.buildType(new ColumnDesc(column.getColumnName(), column.getOptType().toEPL()), services.getClasspathImportServiceCompileTime()); descriptor = new TableColumnDescTyped(positionInDeclaration, column.getColumnName(), unresolvedType, column.getPrimaryKey() == null ? false : column.getPrimaryKey()); } descriptors.add(descriptor); positionInDeclaration++; } return descriptors; }
boolean hasProperties = false; if ((columns != null) && (!columns.isEmpty())) { properties = EventTypeUtility.buildType(columns, null, services.getClasspathImportServiceCompileTime(), services.getEventTypeCompileTimeResolver()); hasProperties = true; } else {
if (spec.getTypes().isEmpty()) { EventUnderlyingType representation = EventRepresentationUtil.getRepresentation(annotations, services.getConfiguration(), spec.getAssignedType()); Map<String, Object> typing = EventTypeUtility.buildType(spec.getColumns(), spec.getCopyFrom(), services.getClasspathImportServiceCompileTime(), services.getEventTypeCompileTimeResolver()); Map<String, Object> compiledTyping = EventTypeUtility.compileMapTypeProperties(typing, services.getEventTypeCompileTimeResolver());