I have following entity configuration:
entity AirplaneModelSeat {
id Long,
seatNo String required
}
relationship ManyToOne {
AirplaneModelSeat{modelId(model)} to AirplaneModel
}
This entity configuration creates such a table:
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| seat_no | varchar(255) | NO | | NULL | |
| model_id_id | bigint(20) | YES | MUL | NULL | |
+-------------+--------------+------+-----+---------+----------------+
How can I apply unique constraint for (seat_no, model_id_id) column combination in JDL-Studio?
If this is not possible in JDL-Studioi is there any other to accomplish this?
As far as I know, constraints are not part of JDL in a general manner. You can define such things as validations. But as for the Domain, the unique constraint is not that general anymore, it is a database level constraint, where it has to be applied.
For this, JHipster includes Liquibase. So you can find the changelog, defining the entity constraints in "src/main/resources/config/liquibase", and add a
<addUniqueConstraint tableName="airplane_model_seat" columnNames="seat_no, model_id_id"/>
to that changelog.
If you already started your application used h2 disk persistent databse, make a mvn clean / ./gradlew clean before starting your app again.
In addition to the Liquibase configuration in David's answer I suggest you also add the relevant JPA annotations to your Entity. Here is an example how:
#Table(name = "table_name",
uniqueConstraints = {#UniqueConstraint(columnNames = {"field_1", "field_2"})})
Note that since in this case #UniqueConstraint is applied at Entity (i.e. Table) level, you can combine multiple fields into a composite unique key.
In addition to Oerd's answer ^_^ In addition to the Liquibase configuration in David's answer I suggest you also add the relevant JPA annotations to your Entity.
If only To ensure a field value is unique you can write
#Column(unique=true)
String username;
The #UniqueConstraint annotation is for annotating multiple unique keys at the table level.
And also for Liquibase configuration, iff only To ensure a field value is unique you can write
<column name="username" type="varchar(255)">
<constraints nullable="true" unique="true" />
</column>
Related
I have created the materialized view in ADX with backfill property set . If I have to check the backfill property after its creation, How can I check it using the kusto command .
Example :
.create async ifnotexists materialized-view with (**backfill=true, docString="Asset Trends",effectiveDateTime=datetime(2022-06-08)**) AssetTrend on table Variables {
Variables | summarize Normal = countif(value<=1), CheckSUM = countif(value>1 and value<=250), OutofSpecification = countif(value>250 and value<=500), MaintenanceRequired = countif(value>500 and value<=750), Failure = countif(value>750 and value<=1000) by bin(timestamp,1s) , model, objectId, tenantId, variable }
Update (following Yifat's comment):
.show materialized-view MyMV
| project EffectiveDateTime
EffectiveDateTime
2022-08-29T11:25:48.2667521Z
Search for the relevant ClientActivityId and then run this:
.show commands
| where ClientActivityId == ...
| project ResourcesUtilization.ScannedExtentsStatistics
| evaluate bag_unpack(ResourcesUtilization_ScannedExtentsStatistics)
| distinct *
MaxDataScannedTime
MinDataScannedTime
ScannedExtentsCount
ScannedRowsCount
TotalExtentsCount
TotalRowsCount
2022-08-29T11:25:52.0952791Z
2022-08-29T11:25:48.2667522Z
8
120000000
8
120000000
Here is the information from the table the MV was based on:
.show table r100k details
| project TotalExtents, TotalRowCount, MinExtentsCreationTime, MaxExtentsCreationTime
TotalExtents
TotalRowCount
MinExtentsCreationTime
MaxExtentsCreationTime
8
120000000
2022-08-29T11:25:48.2667522Z
2022-08-29T11:25:52.0952791Z
I want to perform a subselect on a related set of data. That subdata needs to be filtered using data from the main query:
customEvents
| extend envId = tostring(customDimensions.EnvironmentId)
| extend organisation = tostring(customDimensions.OrganisationName)
| extend version = tostring(customDimensions.Version)
| extend app = tostring(customDimensions.Appname)
| where customDimensions.EventName contains "ApiSessionStartStart"
| extend dbInfo = toscalar(
customEvents
| extend dbInfo = tostring(customDimensions.dbInfo)
| extend serverEnvId = tostring(customDimensions.EnvironmentId)
| where customDimensions.EventName == "ServiceSessionStart" or customDimensions.EventName == "ServiceSessionContinuation"
| where serverEnvId = envId // This gives and error
| project dbInfo
| take 1)
| order by timestamp desc
| project timestamp, customDimensions.OrganisationName, customDimensions.Version, customDimensions.onBehalfOf, customDimensions.userId, customDimensions.Appname, customDimensions.apiKey, customDimensions.remoteIp, session_Id , dbInfo, envId
The above query results in an error:
Failed to resolve entity 'envId'
How can I filter the data in the subselect based on the field envId in the main query?
i believe you'd need to use join instead, where you'd join to get that value from the second query
docs for join: https://docs.loganalytics.io/docs/Language-Reference/Tabular-operators/join-operator
the left hand side of the join is your "outer" query, and the right hand side of the join would be that "inner" query, though instead of doing take 1, you'd probably do a simpler query that just gets distinct values of serverEnvId, dbInfo
When grabbing search result using Azure Log Analytics Search REST API
I'm able to receive only the first 5000 results (as by the specs, at the top of the document), but know there are many more (by the "total" attribute in the metadata in the response).
Is there a way to paginate so to get the entire result set?
One hacky way would be to attempt to break down the desired time-range iteratively until the "total" is less than 5000 for that timeframe, and do this process iteratively for the entire desired time-range - but this is guesswork that will cost many redundant requests.
While it doesn't appear to be a way to paginate using the REST API itself, you can use your query to perform the pagination. The two key operators here are TOP and SKIP:
Suppose you want page n with pagesize x (starting at page 1), then append to your query:
query | skip (n-1) * x | top x.
For a full reference list, see https://learn.microsoft.com/en-us/azure/log-analytics/log-analytics-search-reference
Yes, skip operation is not available anymore but if you want create pagination there is still an option. You need to count total count of entries, use a simple math and two opposite sortings.
Prerequisites for this query are values: ContainerName, Namespace, Page, PageSize.
I'm using it in Workbook where these values are set by fields.
let containers = KubePodInventory
| where ContainerName matches regex '^.*{ContainerName}$' and Namespace == '{Namespace}'
| distinct ContainerID
| project ContainerID;
let TotalCount = toscalar(ContainerLog
| where ContainerID in (containers)
| where LogEntry contains '{SearchText}'
| summarize CountOfLogs = count()
| project CountOfLogs);
ContainerLog
| where ContainerID in (containers)
| where LogEntry contains '{SearchText}'
| extend Log=replace(#'(\x1b\[[0-9]*m|\x1b\[0 [0-9]*m)','', LogEntry)
| project TimeGenerated, Log
| sort by TimeGenerated asc
| take {PageSize}*{Page}
| top iff({PageSize}*{Page} > TotalCount, TotalCount - ({PageSize}*({Page} - 1)) , {PageSize}) by TimeGenerated desc;
// The '| extend' is not needed if in logs are not the annoying special characters
I have these model.
var User = this.sequelize.define('user', {name: String})
var Account = this.sequelize.define('account', {account: String})
User.hasMany(Account);
Account.belongsTo(User);
Now, assume that in TABLE User, i already have:
| id | name |
|----|--------|
| 1 | Maat |
| 2 | MatieL |
Now, i want to create an account but i only want to use User ID not user instance.
Account.create({name: 'MyAccount', userid: 1});
But after that, the row show in TABLE Account is:
| id | account |userId|
|----|-------------|------|
| 1 | MyAccount | NULL |
I don't know why it doesn't work. Please suggest me if you know the answer.
Thank you.
PS:
I know that i can create account instance by another way by firstly finding userinstance by userid then after create account then call userinstance.addAccount(account), but i don't want to use that way because it cost more queries.
PS2: The solution is userId with i capital, not userid
Hi The default foregin key is user_id and not userid
Refer http://docs.sequelizejs.com/en/1.7.0/docs/associations/#foreign-keys
Using Relational Stores, is it possible to do a one-to-many join from the ActivePivot store to a joining store. Suppose my ActivePivot store joins to another store on SOME_ID, but the key for the other store is SOME_ID,SOME_TYPE. Then it is possible to have:
AP_STORE SOME_ID | JOIN_STORE SOME_ID | JOIN_STORE SOME_TYPE
------------------------------------------------------------
1 | 1 | TYPE1
1 | 1 | TYPE2
However, when the join is attempted, the following error is raised, because there is not a unique entry in the joining store:
Caused by: com.quartetfs.fwk.QuartetRuntimeException: Impossible to find exactly 1 entry from store with key: Key
I can see why there is a problem, because there single record in the AP store that really needs to become two separate records that join to each of the records in the join store, respectively, but I guess that can't happen unless JOIN_STORE:SOME_TYPE is also a field in the AP store.
Is there a way to make such a one-to-many join from the AP store happen?
Thanks
Edit: To be clear, SOME_TYPE does not exist in the AP store (even under a different name). I have joined on all the common fields, but there are more than one matching entries in the joining store. The matching entries differ on a field that is not common and does not exist in the AP store.
If I try to add a foreign key that does not exist in the AP store (even under a different name), I get:
Caused by: com.quartetfs.fwk.QuartetRuntimeException: com.quartetfs.fwk.AgentException: On join 'AP_STORE=>JOIN_STORE' the store 'AP_STORE' does not contain the foreign key 'FIELD_ONLY_IN_JOIN_STORE' in its fields:
A relational store join does not duplicate the data.
You cannot, using the join of the relational stores, join one entry to multiple ones.
You cannot use a multiple producing calculator with the relational stores neither.
Depending of your project architecture and workflow, you can consider adding a logic in the transaction handler used to feed your AP_Store. In this transaction handler, you could retrieve the entries of your Join_Store in order to duplicate the entries of your AP_Store.
You'll first need to change your AP_Store keys by adding a new fields used to differentiate your duplicates.
AP_STORE SOME_ID | AP_STORE SOME_DUPLICATE_ID |JOIN_STORE SOME_ID | JOIN_STORE SOME_TYPE
-----------------------------------------------------------------------------------------
1 | 1 | 1 | TYPE1
1 | 2 | 1 | TYPE2
For your transaction handler you can inject the StoresUniverse in order to retrieve your Join_Store and then do a search using the SOME_ID value on the Join_Store to retrieve the number of duplicates you'll need to create:
IRelationalStore joinStore = storeUniverse.get("Join_Store");
List<IRelationalEntry> joinEntries = joinStore.search("SOME_ID",apStoreObject.get("SOME_ID"));
for(int i = 0; i < joinEntries.size(); i++) {
// Clone apStoreObject, add a SOME_DUPLICATE_ID value and add it to the list of objects to add in your AP_Store
}
To join your AP Store to the joiningStore, you need to give a set of fields, common between the 2 stores. There is no constrain like these fields being key fields of each of the store.
Then, if you have a field representing SOME_TYPE in your AP store, just add it as a foreign key.
<property name="joins">
<list>
<bean class="com.quartetfs.tech.store.description.impl.JoinDescription">
<property name="targetStoreName" value="JoiningStore" />
<property name="foreignKeys" value="SOME_TYPE" />
</bean>
</list>
</property>
If the field has different names in the joined store and the joining store, you can use a map to describe the relationship between the joined store foreign key and the associated field in the joining field:
<property name="joins">
<list>
<bean class="com.quartetfs.tech.store.description.impl.JoinDescription">
<property name="targetStoreName" value="JoiningStore" />
<property name="foreignKeyMap" >
<map>
<entry key="AP_SOME_TYPE" value="SOME_TYPE" />
</map>
</property>
</bean>
</list>
</property>